Search in sources :

Example 1 with PixelWriter

use of javafx.scene.image.PixelWriter in project processing by processing.

the class PGraphicsFX2D method flushPixels.

protected void flushPixels() {
    boolean hasPixels = modified && pixels != null;
    if (hasPixels) {
        // If the user has been manipulating individual pixels,
        // the changes need to be copied to the screen before
        // drawing any new geometry.
        int mx1 = getModifiedX1();
        int mx2 = getModifiedX2();
        int my1 = getModifiedY1();
        int my2 = getModifiedY2();
        int mw = mx2 - mx1;
        int mh = my2 - my1;
        PixelWriter pw = context.getPixelWriter();
        pw.setPixels(mx1, my1, mw, mh, argbFormat, pixels, mx1 + my1 * pixelWidth, pixelWidth);
    }
    modified = false;
}
Also used : PixelWriter(javafx.scene.image.PixelWriter)

Example 2 with PixelWriter

use of javafx.scene.image.PixelWriter in project FXyzLib by Birdasaur.

the class Palette method createPalette.

public Image createPalette(boolean save) {
    if (numColors < 1) {
        return null;
    }
    // try to create a square image
    width = (int) Math.sqrt(numColors);
    height = numColors / width;
    imgPalette = new WritableImage(width, height);
    PixelWriter pw = ((WritableImage) imgPalette).getPixelWriter();
    AtomicInteger count = new AtomicInteger();
    IntStream.range(0, height).boxed().forEach(y -> IntStream.range(0, width).boxed().forEach(x -> pw.setColor(x, y, getColor(count.getAndIncrement()))));
    if (save) {
        saveImage();
    }
    return imgPalette;
}
Also used : IntStream(java.util.stream.IntStream) Color(javafx.scene.paint.Color) Arrays(java.util.Arrays) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) File(java.io.File) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) PixelWriter(javafx.scene.image.PixelWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SwingFXUtils(javafx.embed.swing.SwingFXUtils) ImageIO(javax.imageio.ImageIO) Image(javafx.scene.image.Image) WritableImage(javafx.scene.image.WritableImage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PixelWriter(javafx.scene.image.PixelWriter)

Example 3 with PixelWriter

use of javafx.scene.image.PixelWriter in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method getSLCricle.

private Image getSLCricle(int width, int height, List<Stop> stops) {
    WritableImage raster = new WritableImage(width, height);
    PixelWriter pixelWriter = raster.getPixelWriter();
    Point2D center = new Point2D((double) width / 2, (double) height / 2);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double dy = x - center.getX();
            double dx = y - center.getY();
            pixelWriter.setColor(x, y, getColor(dx, dy));
        }
    }
    return raster;
}
Also used : WritableImage(javafx.scene.image.WritableImage) Point2D(javafx.geometry.Point2D) PixelWriter(javafx.scene.image.PixelWriter)

Example 4 with PixelWriter

use of javafx.scene.image.PixelWriter in project JFoenix by jfoenixadmin.

the class JFXColorPickerUI method getHuesCircle.

private Image getHuesCircle(int width, int height, List<Stop> stops) {
    WritableImage raster = new WritableImage(width, height);
    PixelWriter pixelWriter = raster.getPixelWriter();
    Point2D center = new Point2D((double) width / 2, (double) height / 2);
    double rsmall = 0.8 * width / 2;
    double rbig = (double) width / 2;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double dx = x - center.getX();
            double dy = y - center.getY();
            double distance = Math.sqrt((dx * dx) + (dy * dy));
            double o = Math.atan2(dy, dx);
            if (distance > rsmall && distance < rbig) {
                double H = map(o, -Math.PI, Math.PI, 0, 255);
                double S = 255;
                double L = 152;
                pixelWriter.setColor(x, y, HSL2RGB(H, S, L));
            }
        }
    }
    return raster;
}
Also used : WritableImage(javafx.scene.image.WritableImage) Point2D(javafx.geometry.Point2D) PixelWriter(javafx.scene.image.PixelWriter)

Example 5 with PixelWriter

use of javafx.scene.image.PixelWriter in project processing by processing.

the class PGraphicsFX2D method setImpl.

@Override
protected void setImpl(PImage sourceImage, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int targetX, int targetY) {
    sourceImage.loadPixels();
    int sourceOffset = sourceX + sourceImage.pixelWidth * sourceY;
    PixelWriter pw = context.getPixelWriter();
    pw.setPixels(targetX, targetY, sourceWidth, sourceHeight, argbFormat, sourceImage.pixels, sourceOffset, sourceImage.pixelWidth);
    // Let's keep them loaded
    if (loaded) {
        int sourceStride = sourceImage.pixelWidth;
        int targetStride = pixelWidth;
        int targetOffset = targetX + targetY * targetStride;
        for (int i = 0; i < sourceHeight; i++) {
            System.arraycopy(sourceImage.pixels, sourceOffset + i * sourceStride, pixels, targetOffset + i * targetStride, sourceWidth);
        }
    }
}
Also used : PixelWriter(javafx.scene.image.PixelWriter)

Aggregations

PixelWriter (javafx.scene.image.PixelWriter)5 WritableImage (javafx.scene.image.WritableImage)3 Point2D (javafx.geometry.Point2D)2 File (java.io.File)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DoubleStream (java.util.stream.DoubleStream)1 IntStream (java.util.stream.IntStream)1 SwingFXUtils (javafx.embed.swing.SwingFXUtils)1 Image (javafx.scene.image.Image)1 Color (javafx.scene.paint.Color)1 ImageIO (javax.imageio.ImageIO)1