use of javafx.scene.image.PixelReader in project processing by processing.
the class PGraphicsFX2D method loadPixels.
// //////////////////////////////////////////////////////////////
//
// // COLOR MODE
//
// // All colorMode() variations are inherited from PGraphics.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR CALC
//
// // colorCalc() and colorCalcARGB() inherited from PGraphics.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR DATATYPE STUFFING
//
// // final color() variations inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR DATATYPE EXTRACTION
//
// // final methods alpha, red, green, blue,
// // hue, saturation, and brightness all inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR DATATYPE INTERPOLATION
//
// // both lerpColor variants inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // BEGIN/END RAW
//
//
// @Override
// public void beginRaw(PGraphics recorderRaw) {
// showMethodWarning("beginRaw");
// }
//
//
// @Override
// public void endRaw() {
// showMethodWarning("endRaw");
// }
//
//
//
// //////////////////////////////////////////////////////////////
//
// // WARNINGS and EXCEPTIONS
//
// // showWarning and showException inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // RENDERER SUPPORT QUERIES
//
//
// //public boolean displayable() // true
//
//
// //public boolean is2D() // true
//
//
// //public boolean is3D() // false
//////////////////////////////////////////////////////////////
// PIMAGE METHODS
@Override
public void loadPixels() {
if ((pixels == null) || (pixels.length != pixelWidth * pixelHeight)) {
pixels = new int[pixelWidth * pixelHeight];
loaded = false;
}
if (!loaded) {
if (snapshotImage == null || snapshotImage.getWidth() != pixelWidth || snapshotImage.getHeight() != pixelHeight) {
snapshotImage = new WritableImage(pixelWidth, pixelHeight);
}
SnapshotParameters sp = new SnapshotParameters();
if (pixelDensity != 1) {
sp.setTransform(Transform.scale(pixelDensity, pixelDensity));
}
snapshotImage = ((PSurfaceFX) surface).canvas.snapshot(sp, snapshotImage);
PixelReader pr = snapshotImage.getPixelReader();
pr.getPixels(0, 0, pixelWidth, pixelHeight, argbFormat, pixels, 0, pixelWidth);
loaded = true;
modified = false;
}
}
use of javafx.scene.image.PixelReader in project Krothium-Launcher by DarkLBP.
the class Kernel method getProfileIcon.
/**
* Gets a profile icon from the icons map
*
* @param p The desired profile icon
* @return The image with the profile icon
*/
public Image getProfileIcon(ProfileIcon p) {
if (iconCache.containsKey(p)) {
return iconCache.get(p);
}
WritableImage wi = new WritableImage(68, 68);
PixelWriter pw = wi.getPixelWriter();
int blockX = 0;
int blockY = 0;
PixelReader pr = profileIcons.getPixelReader();
switch(p) {
case LEAVES_OAK:
blockX = 0;
blockY = 0;
break;
case BEDROCK:
blockX = 1;
blockY = 0;
break;
case CLAY:
blockX = 2;
blockY = 0;
break;
case DIAMOND_BLOCK:
blockX = 3;
blockY = 0;
break;
case END_STONE:
blockX = 4;
blockY = 0;
break;
case GRAVEL:
blockX = 5;
blockY = 0;
break;
case LOG_BIRCH:
blockX = 6;
blockY = 0;
break;
case PLANKS_OAK:
blockX = 7;
blockY = 0;
break;
case TNT:
blockX = 8;
blockY = 0;
break;
case BRICK:
blockX = 0;
blockY = 1;
break;
case CHEST:
blockX = 1;
blockY = 1;
break;
case COAL_BLOCK:
blockX = 2;
blockY = 1;
break;
case DIAMOND_ORE:
blockX = 3;
blockY = 1;
break;
case FARMLAND:
blockX = 4;
blockY = 1;
break;
case HARDENED_CLAY:
blockX = 5;
blockY = 1;
break;
case LOG_DARKOAK:
blockX = 6;
blockY = 1;
break;
case PLANKS_SPRUCE:
blockX = 7;
blockY = 1;
break;
case WOOL:
blockX = 8;
blockY = 1;
break;
case COAL_ORE:
blockX = 0;
blockY = 2;
break;
case COBBLESTONE:
blockX = 1;
blockY = 2;
break;
case // Default for Latest Snapshot
CRAFTING_TABLE:
blockX = 2;
blockY = 2;
break;
case DIRT:
blockX = 3;
blockY = 2;
break;
case // Default for custom profiles
FURNACE:
blockX = 4;
blockY = 2;
break;
case ICE_PACKED:
blockX = 5;
blockY = 2;
break;
case LOG_JUNGLE:
blockX = 6;
blockY = 2;
break;
case QUARTZ_ORE:
blockX = 7;
blockY = 2;
break;
case DIRT_PODZOL:
blockX = 0;
blockY = 3;
break;
case DIRT_SNOW:
blockX = 1;
blockY = 3;
break;
case EMERALD_BLOCK:
blockX = 2;
blockY = 3;
break;
case EMERALD_ORE:
blockX = 3;
blockY = 3;
break;
case FURNACE_ON:
blockX = 4;
blockY = 3;
break;
case IRON_BLOCK:
blockX = 5;
blockY = 3;
break;
case LOG_OAK:
blockX = 6;
blockY = 3;
break;
case RED_SAND:
blockX = 7;
blockY = 3;
break;
case GLASS:
blockX = 0;
blockY = 4;
break;
case GLOWSTONE:
blockX = 1;
blockY = 4;
break;
case GOLD_BLOCK:
blockX = 2;
blockY = 4;
break;
case GOLD_ORE:
blockX = 3;
blockY = 4;
break;
case // Default for Latest Release
GRASS:
blockX = 4;
blockY = 4;
break;
case IRON_ORE:
blockX = 5;
blockY = 4;
break;
case LOG_SPRUCE:
blockX = 6;
blockY = 4;
break;
case RED_SANDSTONE:
blockX = 7;
blockY = 4;
break;
case LAPIS_ORE:
blockX = 0;
blockY = 5;
break;
case LEAVES_BIRCH:
blockX = 1;
blockY = 5;
break;
case LEAVES_JUNGLE:
blockX = 2;
blockY = 5;
break;
case BOOKSHELF:
blockX = 3;
blockY = 5;
break;
case LEAVES_SPRUCE:
blockX = 4;
blockY = 5;
break;
case LOG_ACACIA:
blockX = 5;
blockY = 5;
break;
case MYCELIUM:
blockX = 6;
blockY = 5;
break;
case REDSTONE_BLOCK:
blockX = 7;
blockY = 5;
break;
case NETHER_BRICK:
blockX = 0;
blockY = 6;
break;
case NETHERRACK:
blockX = 1;
blockY = 6;
break;
case OBSIDIAN:
blockX = 2;
blockY = 6;
break;
case PLANKS_ACACIA:
blockX = 3;
blockY = 6;
break;
case PLANKS_BIRCH:
blockX = 4;
blockY = 6;
break;
case PLANKS_DARKOAK:
blockX = 5;
blockY = 6;
break;
case PLANKS_JUNGLE:
blockX = 6;
blockY = 6;
break;
case REDSTONE_ORE:
blockX = 7;
blockY = 6;
break;
case SAND:
blockX = 0;
blockY = 7;
break;
case SANDSTONE:
blockX = 1;
blockY = 7;
break;
case SNOW:
blockX = 2;
blockY = 7;
break;
case SOUL_SAND:
blockX = 3;
blockY = 7;
break;
case STONE:
blockX = 4;
blockY = 7;
break;
case STONE_ANDESITE:
blockX = 5;
blockY = 7;
break;
case STONE_DIORITE:
blockX = 6;
blockY = 7;
break;
case STONE_GRANITE:
blockX = 7;
blockY = 7;
break;
}
pw.setPixels(0, 0, 68, 68, pr, blockX * 68, blockY * 68);
iconCache.put(p, wi);
return wi;
}
use of javafx.scene.image.PixelReader in project tokentool by RPTools.
the class ImageUtil method autoCropImage.
/*
* Crop image to smallest width/height based on transparency
*/
private static Image autoCropImage(Image imageSource) {
ImageView croppedImageView = new ImageView(imageSource);
PixelReader pixelReader = imageSource.getPixelReader();
int imageWidth = (int) imageSource.getWidth();
int imageHeight = (int) imageSource.getHeight();
int minX = imageWidth, minY = imageHeight, maxX = 0, maxY = 0;
// Find the first and last pixels that are not transparent to create a bounding viewport
for (int readY = 0; readY < imageHeight; readY++) {
for (int readX = 0; readX < imageWidth; readX++) {
Color pixelColor = pixelReader.getColor(readX, readY);
if (!pixelColor.equals(Color.TRANSPARENT)) {
if (readX < minX)
minX = readX;
if (readX > maxX)
maxX = readX;
if (readY < minY)
minY = readY;
if (readY > maxY)
maxY = readY;
}
}
}
if (maxX - minX <= 0 || maxY - minY <= 0)
return new WritableImage(1, 1);
// Create a viewport to clip the image using snapshot
Rectangle2D viewPort = new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
SnapshotParameters parameter = new SnapshotParameters();
parameter.setViewport(viewPort);
parameter.setFill(Color.TRANSPARENT);
return croppedImageView.snapshot(parameter, null);
}
use of javafx.scene.image.PixelReader in project tokentool by RPTools.
the class ImageUtil method resizeCanvas.
/*
* Resize the overall image width/height without scaling the actual image, eg resize the canvas
*/
public static Image resizeCanvas(Image imageSource, int newWidth, int newHeight, int offsetX, int offsetY) {
int sourceWidth = (int) imageSource.getWidth();
int sourceHeight = (int) imageSource.getHeight();
// No work needed here...
if (sourceWidth == newWidth && sourceHeight == newHeight)
return imageSource;
WritableImage outputImage = new WritableImage(newWidth, newHeight);
PixelReader pixelReader = imageSource.getPixelReader();
PixelWriter pixelWriter = outputImage.getPixelWriter();
WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();
int[] buffer = new int[sourceWidth * sourceHeight];
pixelReader.getPixels(0, 0, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
pixelWriter.setPixels(offsetX, offsetY, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
return outputImage;
}
use of javafx.scene.image.PixelReader in project latexdraw by arnobl.
the class HelperTest method computeSnapshotSimilarity.
/**
* Compute the similarity of two JavaFX images.
* @param image1 The first image to test.
* @param image2 The second image to test.
* @return A double value in [0;100] corresponding to the similarity between the two images (pixel comparison).
* @throws NullPointerException If image1 or image2 is null.
*/
default double computeSnapshotSimilarity(final Image image1, final Image image2) {
final int width = (int) image1.getWidth();
final int height = (int) image1.getHeight();
final PixelReader reader1 = image1.getPixelReader();
final PixelReader reader2 = image2.getPixelReader();
final double nbNonSimilarPixels = IntStream.range(0, width).parallel().mapToLong(i -> IntStream.range(0, height).parallel().filter(j -> reader1.getArgb(i, j) != reader2.getArgb(i, j)).count()).sum();
return 100d - nbNonSimilarPixels / (width * height) * 100d;
}
Aggregations