Java Code Examples for javafx.scene.image.WritableImage

The following examples show how to use javafx.scene.image.WritableImage. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: chart-fx   Source File: WriteFxImage.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * copy the given Image to a WritableImage
 * 
 * @param image the input image
 * @return clone of image
 */
public static WritableImage clone(Image image) {
    int height = (int) image.getHeight();
    int width = (int) image.getWidth();
    WritableImage writableImage = WritableImageCache.getInstance().getImage(width, height);
    PixelWriter pixelWriter = writableImage.getPixelWriter();
    if (pixelWriter == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }

    final PixelReader pixelReader = image.getPixelReader();
    if (pixelReader == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            Color color = pixelReader.getColor(x, y);
            pixelWriter.setColor(x, y, color);
        }
    }
    return writableImage;
}
 
Example 2
private void updatePlaceholder(Node newView) {
    if (view.getWidth() > 0 && view.getHeight() > 0) {
        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        Image placeholderImage = view.snapshot(parameters,
                new WritableImage((int) view.getWidth(), (int) view.getHeight()));
        placeholder.setImage(placeholderImage);
        placeholder.setFitWidth(placeholderImage.getWidth());
        placeholder.setFitHeight(placeholderImage.getHeight());
    } else {
        placeholder.setImage(null);
    }
    placeholder.setVisible(true);
    placeholder.setOpacity(1.0);
    view.getChildren().setAll(placeholder, newView);
    placeholder.toFront();
}
 
Example 3
Source Project: chart-fx   Source File: PeriodicScreenCapture.java    License: Apache License 2.0 6 votes vote down vote up
public void performScreenCapture() {
    try {
        final WritableImage image = primaryScene.snapshot(null);
        // open save in separate thread
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                writeImage(image);
            }
        }, 0);

        LOGGER.debug("this is called periodic on UI thread");
    } catch (final Exception e) {
        // continue at all costs
        LOGGER.error("error while writing screen captured image to file", e);
    }
}
 
Example 4
/**
 * Creates a thumbnail from the given selection in the given file.
 * @param templateFile The file of the future thumbnail.
 * @param selection The set of shapes composing the template.
 */
private void createTemplateThumbnail(final File templateFile, final javafx.scene.Group selection) {
	final Bounds bounds = selection.getBoundsInParent();
	final double scale = 70d / Math.max(bounds.getWidth(), bounds.getHeight());
	final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale));
	final SnapshotParameters snapshotParameters = new SnapshotParameters();

	snapshotParameters.setFill(Color.WHITE);
	snapshotParameters.setTransform(new Scale(scale, scale));
	selection.snapshot(snapshotParameters, img);

	final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(img, null);

	try {
		ImageIO.write(bufferedImage, "png", templateFile);  //NON-NLS
	}catch(final IOException ex) {
		BadaboomCollector.INSTANCE.add(ex);
	}
	bufferedImage.flush();
}
 
Example 5
Source Project: chart-fx   Source File: WritableImageCacheTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testIterators() {
    final WritableImageCache cache = new WritableImageCache();
    assertEquals(0, cache.size(), "initial cache size");

    for (int i = 0; i < N_INITIAL_CACHE_OBJECTS; i++) {
        cache.add(new WritableImage(N_IMAGE_WIDTH, N_IMAGE_HEIGHT));
    }
    assertEquals(N_INITIAL_CACHE_OBJECTS, cache.size(), "allocated dummy arrays -- N.B. if this fails the testing environment likely has not have enough memory");

    final java.util.Iterator<WritableImage> iter = cache.iterator();
    int count = 0;
    while (iter.hasNext()) {
        final WritableImage element = iter.next();
        if (count == 0 || element == null) {
            iter.remove();
        }
        count++;
    }
    assertEquals(N_INITIAL_CACHE_OBJECTS, count);
}
 
Example 6
Source Project: chart-fx   Source File: WritableImageCacheTests.java    License: Apache License 2.0 6 votes vote down vote up
private static double performanceCheckCached() {
    final WritableImageCache cache = new WritableImageCache();
    cache.add(new WritableImage(N_IMAGE_WIDTH, N_IMAGE_HEIGHT));

    final long start = System.nanoTime();
    for (int i = 0; i < N_ITERATIONS; i++) {
        WritableImage image = cache.getImage(N_IMAGE_WIDTH, N_IMAGE_HEIGHT);

        // simple check to minimise JIT optimisations
        if ((int) image.getWidth() != N_IMAGE_WIDTH) {
            throw new IllegalStateException("should not occur");
        }

        cache.add(image);
        image = null;
    }

    final long stop = System.nanoTime();

    return (stop - start) / (double) N_ITERATIONS;
}
 
Example 7
Source Project: chart-fx   Source File: WritableImageCacheTests.java    License: Apache License 2.0 6 votes vote down vote up
private static double performanceCheckClassic() {
    final long start = System.nanoTime();
    for (int i = 0; i < N_ITERATIONS; i++) {
        WritableImage image = new WritableImage(N_IMAGE_WIDTH, N_IMAGE_HEIGHT);

        // simple check to minimise JIT optimisations
        if ((int) image.getWidth() != N_IMAGE_WIDTH) {
            throw new IllegalStateException("should not occur");
        }

        image = null;
    }

    final long stop = System.nanoTime();

    return (stop - start) / (double) N_ITERATIONS;
}
 
Example 8
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);

// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/radialmenu-snapshot-"
	+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
    ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
	    outFile);
} catch (final IOException ex) {
    System.out.println(ex.getMessage());
}

snapshotCounter++;
   }
 
Example 9
Source Project: metastone   Source File: DigitFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void saveAllDigits() {
	Stage stage = new Stage(StageStyle.TRANSPARENT);
	DigitTemplate root = new DigitTemplate();
	Scene scene = new Scene(root);
	stage.setScene(scene);
	stage.show();

	SnapshotParameters snapshotParams = new SnapshotParameters();
	snapshotParams.setFill(Color.TRANSPARENT);
	root.digit.setText("-");
	for (int i = 0; i <= 10; i++) {
		WritableImage image = root.digit.snapshot(snapshotParams, null);

		File file = new File("src/" + IconFactory.RESOURCE_PATH + "/img/common/digits/" + root.digit.getText() + ".png");

		try {
			ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
		} catch (IOException e) {
			e.printStackTrace();
		}
		root.digit.setText("" + i);
	}

	stage.close();
}
 
Example 10
Source Project: oim-fx   Source File: HeadImagePanel.java    License: MIT License 6 votes vote down vote up
private void setGrayImage(Image image) {
	if (null != image && !image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			if (null != pixelWriter && null != pixelReader) {
				for (int y = 0; y < imageHeight; y++) {
					for (int x = 0; x < imageWidth; x++) {
						Color color = pixelReader.getColor(x, y);
						color = color.grayscale();
						pixelWriter.setColor(x, y, color);
					}
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
Example 11
Source Project: oim-fx   Source File: HeadImageItemPane.java    License: MIT License 6 votes vote down vote up
private void setGrayImage(Image image) {
	if (null != image&&!image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
Example 12
Source Project: jace   Source File: VideoDHGR.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void displayLores(WritableImage screen, int xOffset, int y, int rowAddress) {
    int c1 = ((RAM128k) computer.getMemory()).getMainMemory().readByte(rowAddress + xOffset) & 0x0FF;
    if ((y & 7) < 4) {
        c1 &= 15;
    } else {
        c1 >>= 4;
    }
    Color color = Palette.color[c1];
    // Unrolled loop, faster
    PixelWriter writer = screen.getPixelWriter();
    int xx = xOffset * 14;
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
}
 
Example 13
@Override
@BackgroundThread
protected void writeData(@NotNull final VarTable vars, final @NotNull Path resultFile) throws IOException {
    super.writeData(vars, resultFile);

    final Color color = UiUtils.from(vars.get(PROP_COLOR, ColorRGBA.class));

    final int width = vars.getInteger(PROP_WIDTH);
    final int height = vars.getInteger(PROP_HEIGHT);

    final WritableImage writableImage = new WritableImage(width, height);
    final PixelWriter pixelWriter = writableImage.getPixelWriter();

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            pixelWriter.setColor(i, j, color);
        }
    }

    final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(writableImage, null);

    try (final OutputStream out = Files.newOutputStream(resultFile)) {
        ImageIO.write(bufferedImage, "png", out);
    }
}
 
Example 14
Source Project: JFoenix   Source File: ExtendedAnimatedFlowContainer.java    License: Apache License 2.0 6 votes vote down vote up
private void updatePlaceholder(Node newView) {
    if (view.getWidth() > 0 && view.getHeight() > 0) {
        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        Image placeholderImage = view.snapshot(parameters,
            new WritableImage((int) view.getWidth(), (int) view.getHeight()));
        placeholder.setImage(placeholderImage);
        placeholder.setFitWidth(placeholderImage.getWidth());
        placeholder.setFitHeight(placeholderImage.getHeight());
    } else {
        placeholder.setImage(null);
    }
    placeholder.setVisible(true);
    placeholder.setOpacity(1.0);
    view.getChildren().setAll(placeholder, newView);
    placeholder.toFront();
}
 
Example 15
private Image getQRImage() {
    if (qrImage == null) {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        int qrWidth = 500;
        int qrHeight = 500;
        BitMatrix byteMatrix = null;
        try {
            byteMatrix = qrCodeWriter.encode(getMLURL(), BarcodeFormat.QR_CODE, qrWidth, qrHeight);
        } catch (WriterException ex) {
            LOGGER.log(Level.WARNING, "Error writing QR code", ex);
        }
        qrImage = MatrixToImageWriter.toBufferedImage(byteMatrix);
    }
    WritableImage fxImg = new WritableImage(500, 500);
    SwingFXUtils.toFXImage(qrImage, fxImg);
    return fxImg;
}
 
Example 16
Source Project: mcaselector   Source File: NBTTreeView.java    License: MIT License 6 votes vote down vote up
private void onDragDetected(MouseEvent e) {
	if (getTreeItem() == getTreeView().getRoot()) {
		return;
	}
	Dragboard db = startDragAndDrop(TransferMode.MOVE);
	WritableImage wi = new WritableImage((int) getWidth(), (int) getHeight());
	Image dbImg = snapshot(null, wi);
	db.setDragView(dbImg);
	if (USE_DRAGVIEW_OFFSET) {
		db.setDragViewOffsetX(getWidth() / 2);
		db.setDragViewOffsetY(getHeight() / 2);
	}
	ClipboardContent cbc = new ClipboardContent();
	cbc.put(CLIPBOARD_DATAFORMAT, true);
	db.setContent(cbc);
	dragboardContent = getTreeItem();
	e.consume();
}
 
Example 17
Source Project: charts   Source File: HeatMap.java    License: Apache License 2.0 6 votes vote down vote up
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double SPOT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
    super();
    SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
    spotList            = new ArrayList<>();
    spotImages          = new HashMap<>();
    colorMapping        = COLOR_MAPPING;
    mappingGradient     = colorMapping.getGradient();
    fadeColors          = FADE_COLORS;
    radius              = SPOT_RADIUS;
    opacityDistribution = OPACITY_DISTRIBUTION;
    spotImage           = createSpotImage(radius, opacityDistribution);
    monochrome          = new Canvas(WIDTH, HEIGHT);
    ctx                 = monochrome.getGraphicsContext2D();
    monochromeImage     = new WritableImage((int) WIDTH, (int) HEIGHT);
    setImage(heatMap);
    setMouseTransparent(true);
    setOpacity(HEAT_MAP_OPACITY);
    registerListeners();
}
 
Example 18
Source Project: RadialFx   Source File: FuturistDemo.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);

// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/"+getClass().getSimpleName().toLowerCase()+"-"
	+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
    ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
	    outFile);
} catch (final IOException ex) {
    System.out.println(ex.getMessage());
}

snapshotCounter++;
   }
 
Example 19
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 6 votes vote down vote up
public static Image cropInsideFx(Image image, DoubleShape shape, Color bgColor) {
    if (image == null || shape == null || !shape.isValid()
            || bgColor == null) {
        return image;
    }
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (shape.include(x, y)) {
                pixelWriter.setColor(x, y, bgColor);
            } else {
                pixelWriter.setColor(x, y, pixelReader.getColor(x, y));
            }
        }
    }
    return newImage;
}
 
Example 20
Source Project: latexdraw   Source File: HelperTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
default <T extends Node> void assertNotEqualsSnapshot(final T node, final CmdFXVoid toExecBetweenSnap) {
	Bounds bounds = node.getBoundsInLocal();
	final SnapshotParameters params = new SnapshotParameters();

	final WritableImage oracle = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
	Platform.runLater(() -> node.snapshot(params, oracle));
	WaitForAsyncUtils.waitForFxEvents();

	if(toExecBetweenSnap != null) {
		toExecBetweenSnap.execute();
	}

	bounds = node.getBoundsInLocal();
	final WritableImage observ = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
	Platform.runLater(() -> node.snapshot(params, observ));
	WaitForAsyncUtils.waitForFxEvents();

	assertNotEquals("The two snapshots do not differ.", 100d, computeSnapshotSimilarity(oracle, observ), 0.001);
}
 
Example 21
Source Project: MyBox   Source File: FxmlImageManufacture.java    License: Apache License 2.0 6 votes vote down vote up
public static Image horizontalImage(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();

    for (int j = 0; j < height; ++j) {
        int l = 0, r = width - 1;
        while (l <= r) {
            Color cl = pixelReader.getColor(l, j);
            Color cr = pixelReader.getColor(r, j);
            pixelWriter.setColor(l, j, cr);
            pixelWriter.setColor(r, j, cl);
            l++;
            r--;
        }
    }
    return newImage;
}
 
Example 22
Source Project: MyBox   Source File: FxmlControl.java    License: Apache License 2.0 6 votes vote down vote up
public static Image snap(Node node) {
    try {
        final Bounds bounds = node.getLayoutBounds();
        double scale = dpiScale();
        int imageWidth = (int) Math.round(bounds.getWidth() * scale);
        int imageHeight = (int) Math.round(bounds.getHeight() * scale);
        final SnapshotParameters snapPara = new SnapshotParameters();
        snapPara.setFill(Color.TRANSPARENT);
        snapPara.setTransform(javafx.scene.transform.Transform.scale(scale, scale));
        WritableImage snapshot = new WritableImage(imageWidth, imageHeight);
        snapshot = node.snapshot(snapPara, snapshot);
        return snapshot;
    } catch (Exception e) {
        logger.debug(e.toString());
        return null;
    }

}
 
Example 23
Source Project: marathonv5   Source File: ImageOperatorSample.java    License: Apache License 2.0 6 votes vote down vote up
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) {
    PixelWriter pw = img.getPixelWriter();
    double w = img.getWidth();
    double h = img.getHeight();
    double xRatio = 0.0;
    double yRatio = 0.0;
    double hue = 0.0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            xRatio = x/w;
            yRatio = y/h;
            hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset;
            Color c = Color.hsb(hue, 1.0, 1.0);
            pw.setColor(x, y, c);
        }
    }
}
 
Example 24
Source Project: marathonv5   Source File: ImageOperatorSample.java    License: Apache License 2.0 6 votes vote down vote up
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) {
    PixelWriter pw = img.getPixelWriter();
    double w = img.getWidth();
    double h = img.getHeight();
    double xRatio = 0.0;
    double yRatio = 0.0;
    double hue = 0.0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            xRatio = x/w;
            yRatio = y/h;
            hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset;
            Color c = Color.hsb(hue, 1.0, 1.0);
            pw.setColor(x, y, c);
        }
    }
}
 
Example 25
Source Project: Medusa   Source File: Helper.java    License: Apache License 2.0 6 votes vote down vote up
public static final Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    if (Double.compare(WIDTH, 0) <= 0 || Double.compare(HEIGHT, 0) <= 0) return null;
    int                 width                   = (int) WIDTH;
    int                 height                  = (int) HEIGHT;
    double              alphaVariationInPercent = Helper.clamp(0.0, 100.0, 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;
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            final Color  NOISE_COLOR = BW_RND.nextBoolean() ? BRIGHT_COLOR : DARK_COLOR;
            final double NOISE_ALPHA = Helper.clamp(0.0, 1.0, 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;
}
 
Example 26
Source Project: phoebus   Source File: ImageScaling.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void start(final Stage stage)
{
    // Image with red border
    final WritableImage image = new WritableImage(WIDTH, HEIGHT);
    final PixelWriter writer = image.getPixelWriter();
    for (int x=0; x<WIDTH; ++x)
    {
        writer.setColor(x, 0, Color.RED);
        writer.setColor(x, HEIGHT-1, Color.RED);
    }
    for (int y=0; y<HEIGHT; ++y)
    {
        writer.setColor(0, y, Color.RED);
        writer.setColor(WIDTH-1, y, Color.RED);
    }

    // Draw into canvas, scaling 'up'
    final Canvas canvas = new Canvas(800, 600);
    canvas.getGraphicsContext2D().drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight());

    final Scene scene = new Scene(new Group(canvas), canvas.getWidth(), canvas.getHeight());
    stage.setScene(scene);
    stage.show();
}
 
Example 27
Source Project: Enzo   Source File: LcdSkin.java    License: Apache License 2.0 6 votes vote down vote up
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;
    Color noiseColor;
    double noiseAlpha;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
        }
    }
    return IMAGE;
}
 
Example 28
Source Project: jace   Source File: VideoDHGR.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void displayDoubleHires(WritableImage screen, int xOffset, int y, int rowAddress) {
    // Skip odd columns since this does two at once
    if ((xOffset & 0x01) == 1) {
        return;
    }
    int b1 = ((RAM128k) computer.getMemory()).getAuxVideoMemory().readByte(rowAddress + xOffset    );
    int b2 = ((RAM128k) computer.getMemory()).getMainMemory()    .readByte(rowAddress + xOffset    );
    int b3 = ((RAM128k) computer.getMemory()).getAuxVideoMemory().readByte(rowAddress + xOffset + 1);
    int b4 = ((RAM128k) computer.getMemory()).getMainMemory()    .readByte(rowAddress + xOffset + 1);
    int useColOffset = xOffset << 1;
    // This shouldn't be necessary but prevents an index bounds exception when graphics modes are flipped (Race condition?)
    if (useColOffset >= 77) {
        useColOffset = 76;
    }
    useColor[useColOffset    ] = (b1 & 0x80) != 0;
    useColor[useColOffset + 1] = (b2 & 0x80) != 0;
    useColor[useColOffset + 2] = (b3 & 0x80) != 0;
    useColor[useColOffset + 3] = (b4 & 0x80) != 0;
    int dhgrWord  = (0x07f & b1)      ;
        dhgrWord |= (0x07f & b2) <<  7;
        dhgrWord |= (0x07f & b3) << 14;
        dhgrWord |= (0x07f & b4) << 21;
    showDhgr(screen, TIMES_14[xOffset], y, dhgrWord);
}
 
Example 29
Source Project: chart-fx   Source File: ContourDataSetRenderer.java    License: Apache License 2.0 5 votes vote down vote up
private void drawHeatMap(final GraphicsContext gc, final ContourDataSetCache lCache) {
    final long start = ProcessingProfiler.getTimeStamp();

    // N.B. works only since OpenJFX 12!! fall-back for JDK8 is the old implementation
    gc.setImageSmoothing(isSmooth());

    // process z quantisation to colour transform
    final WritableImage image = localCache.convertDataArrayToImage(lCache.reduced, lCache.xSize, lCache.ySize, getColorGradient());
    ProcessingProfiler.getTimeDiff(start, "color map");

    gc.drawImage(image, lCache.xDataPixelMin, lCache.yDataPixelMin, lCache.xDataPixelRange, lCache.yDataPixelRange);

    localCache.add(image);
    ProcessingProfiler.getTimeDiff(start, "drawHeatMap");
}
 
Example 30
Source Project: chart-fx   Source File: ContourDataSetRenderer.java    License: Apache License 2.0 5 votes vote down vote up
private void drawHexagonHeatMap(final GraphicsContext gc, final ContourDataSetCache lCache) {
    final long start = ProcessingProfiler.getTimeStamp();

    // process z quantisation to colour transform
    final WritableImage image = localCache.convertDataArrayToImage(lCache.reduced, lCache.xSize, lCache.ySize, getColorGradient());

    final int tileSize = Math.max(getMinHexTileSizeProperty(), (int) lCache.xAxisWidth / lCache.xSize);
    final int nWidthInTiles = (int) (lCache.xAxisWidth / (tileSize * Math.sqrt(3))) + 1;

    final HexagonMap map2 = new HexagonMap(tileSize, image, nWidthInTiles, (q, r, imagePixelColor, map) -> {
        final Hexagon h = new Hexagon(q, r);
        h.setFill(imagePixelColor);
        h.setStroke(imagePixelColor);

        h.setStrokeWidth(0.5);
        map.addHexagon(h);
    });
    localCache.add(image);

    ProcessingProfiler.getTimeDiff(start, "drawHexagonMap - prepare");
    final double scaleX = lCache.xDataPixelRange / lCache.xAxisWidth;
    final double scaleY = lCache.yDataPixelRange / lCache.yAxisHeight;

    gc.save();
    gc.translate(lCache.xDataPixelMin, lCache.yDataPixelMin);
    gc.scale(scaleX, scaleY);

    map2.render(gc.getCanvas());
    gc.restore();

    // gc.drawImage(image, lCache.xDataPixelMin, lCache.yDataPixelMin, lCache.xDataPixelRange,
    // lCache.yDataPixelRange);

    ProcessingProfiler.getTimeDiff(start, "drawHexagonMap");
}