Search in sources :

Example 11 with PixelReader

use of javafx.scene.image.PixelReader in project StegMeister by GaleForce89.

the class BasicEncoder method encodeImage.

public Image encodeImage(Image image, String message) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    WritableImage copy = new WritableImage(image.getPixelReader(), width, height);
    PixelWriter writer = copy.getPixelWriter();
    PixelReader reader = image.getPixelReader();
    boolean[] bits = encodeImage(message);
    IntStream.range(0, bits.length).mapToObj(i -> new Pair<>(i, reader.getArgb(i % width, i / width))).map(pair -> new Pair<>(pair.getKey(), bits[pair.getKey()] ? pair.getValue() | 1 : pair.getValue() & ~1)).forEach(pair -> {
        int x = pair.getKey() % width;
        int y = pair.getKey() / width;
        writer.setArgb(x, y, pair.getValue());
    });
    return copy;
}
Also used : IntStream(java.util.stream.IntStream) PixelReader(javafx.scene.image.PixelReader) Pair(javafx.util.Pair) PixelWriter(javafx.scene.image.PixelWriter) WritableImage(javafx.scene.image.WritableImage) Image(javafx.scene.image.Image) WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) PixelWriter(javafx.scene.image.PixelWriter) Pair(javafx.util.Pair)

Example 12 with PixelReader

use of javafx.scene.image.PixelReader in project StegMeister by GaleForce89.

the class BasicDecoder method decodeImage.

public String decodeImage(Image image) {
    int imageWidth = (int) image.getWidth();
    int imageHeight = (int) image.getHeight();
    PixelReader reader = image.getPixelReader();
    boolean[] bits = new boolean[imageWidth * imageHeight];
    IntStream.range(0, imageWidth * imageHeight).mapToObj(i -> new Pair<>(i, reader.getArgb(i % imageWidth, i / imageWidth))).forEach(pair -> {
        String binary = Integer.toBinaryString(pair.getValue());
        bits[pair.getKey()] = binary.charAt(binary.length() - 1) == '1';
    });
    // decodes the length
    int length = 0;
    for (int i = 0; i < 32; i++) {
        if (bits[i]) {
            length |= (1 << (31 - i));
        }
    }
    byte[] data = new byte[length];
    for (int i = 0; i < length; i++) for (int j = 0; j < 8; j++) {
        if (bits[32 + i * 8 + j])
            data[i] |= (1 << (7 - j));
    }
    return new String(data);
}
Also used : IntStream(java.util.stream.IntStream) PixelReader(javafx.scene.image.PixelReader) Pair(javafx.util.Pair) Image(javafx.scene.image.Image) PixelReader(javafx.scene.image.PixelReader) Pair(javafx.util.Pair)

Example 13 with PixelReader

use of javafx.scene.image.PixelReader in project jphp by jphp-compiler.

the class DnDTabPaneSkin method tabPane_handleDragStart.

void tabPane_handleDragStart(MouseEvent event) {
    try {
        // $NON-NLS-1$
        Field f_tab = event.getSource().getClass().getDeclaredField("tab");
        f_tab.setAccessible(true);
        Tab t = (Tab) f_tab.get(event.getSource());
        if (t != null && efx_canStartDrag(t)) {
            DRAGGED_TAB = t;
            Node node = (Node) event.getSource();
            Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
            WritableImage snapShot = node.snapshot(new SnapshotParameters(), null);
            PixelReader reader = snapShot.getPixelReader();
            int padX = 10;
            int padY = 10;
            int width = (int) snapShot.getWidth();
            int height = (int) snapShot.getHeight();
            WritableImage image = new WritableImage(width + padX, height + padY);
            PixelWriter writer = image.getPixelWriter();
            int h = 0;
            int v = 0;
            while (h < width + padX) {
                v = 0;
                while (v < height + padY) {
                    if (h >= padX && h <= width + padX && v >= padY && v <= height + padY) {
                        writer.setColor(h, v, reader.getColor(h - padX, v - padY));
                    } else {
                        writer.setColor(h, v, Color.TRANSPARENT);
                    }
                    v++;
                }
                h++;
            }
            db.setDragView(image, image.getWidth(), image.getHeight() * -1);
            ClipboardContent content = new ClipboardContent();
            String data = efx_getClipboardContent(t);
            if (data != null) {
                content.put(TAB_MOVE, data);
            }
            db.setContent(content);
        }
    } catch (Throwable t) {
        // // TODO Auto-generated catch block
        t.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) WritableImage(javafx.scene.image.WritableImage) Tab(javafx.scene.control.Tab) SnapshotParameters(javafx.scene.SnapshotParameters) PixelReader(javafx.scene.image.PixelReader) ClipboardContent(javafx.scene.input.ClipboardContent) Node(javafx.scene.Node) PixelWriter(javafx.scene.image.PixelWriter) Dragboard(javafx.scene.input.Dragboard)

Example 14 with PixelReader

use of javafx.scene.image.PixelReader 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;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) Color(javafx.scene.paint.Color) PixelWriter(javafx.scene.image.PixelWriter)

Example 15 with PixelReader

use of javafx.scene.image.PixelReader in project tokentool by RPTools.

the class ImageUtil method processMagenta.

/*
   * This is for Legacy support but can cause magenta bleed on edges if there is transparency overlap. The preferred overlay storage is now PhotoShop PSD format with layer 1 containing the mask and
   * layer 2 containing the image
   */
private static Image processMagenta(Image inputImage, int colorThreshold, boolean overlayWanted) {
    int imageWidth = (int) inputImage.getWidth();
    int imageHeight = (int) inputImage.getHeight();
    WritableImage outputImage = new WritableImage(imageWidth, imageHeight);
    PixelReader pixelReader = inputImage.getPixelReader();
    PixelWriter pixelWriter = outputImage.getPixelWriter();
    for (int readY = 0; readY < imageHeight; readY++) {
        for (int readX = 0; readX < imageWidth; readX++) {
            Color pixelColor = pixelReader.getColor(readX, readY);
            if (isMagenta(pixelColor, COLOR_THRESHOLD) == overlayWanted)
                pixelWriter.setColor(readX, readY, Color.TRANSPARENT);
            else
                pixelWriter.setColor(readX, readY, pixelColor);
        }
    }
    return outputImage;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) Color(javafx.scene.paint.Color) PixelWriter(javafx.scene.image.PixelWriter)

Aggregations

PixelReader (javafx.scene.image.PixelReader)20 WritableImage (javafx.scene.image.WritableImage)18 PixelWriter (javafx.scene.image.PixelWriter)12 SnapshotParameters (javafx.scene.SnapshotParameters)6 Image (javafx.scene.image.Image)5 Color (javafx.scene.paint.Color)5 IntStream (java.util.stream.IntStream)4 Rectangle2D (javafx.geometry.Rectangle2D)3 Node (javafx.scene.Node)3 Platform (javafx.application.Platform)2 Bounds (javafx.geometry.Bounds)2 ImageView (javafx.scene.image.ImageView)2 Pair (javafx.util.Pair)2 WaitForAsyncUtils (org.testfx.util.WaitForAsyncUtils)2 TimeoutTransition (io.github.interacto.fsm.TimeoutTransition)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1 IntBuffer (java.nio.IntBuffer)1