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;
}
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);
}
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();
}
}
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;
}
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;
}
Aggregations