use of javafx.scene.image.WritableImage 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.WritableImage in project Board-Instrumentation-Framework by intel.
the class ConicalGradient method getImage.
public Image getImage(final double WIDTH, final double HEIGHT) {
int width = (int) WIDTH <= 0 ? 100 : (int) WIDTH;
int height = (int) HEIGHT <= 0 ? 100 : (int) HEIGHT;
Color color = Color.TRANSPARENT;
final WritableImage RASTER = new WritableImage(width, height);
final PixelWriter PIXEL_WRITER = RASTER.getPixelWriter();
if (null == center) {
center = new Point2D(width / 2, height / 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));
distance = Double.compare(distance, 0) == 0 ? 1 : distance;
double angle = Math.abs(Math.toDegrees(Math.acos(dx / distance)));
if (dx >= 0 && dy <= 0) {
angle = 90.0 - angle;
} else if (dx >= 0 && dy >= 0) {
angle += 90.0;
} else if (dx <= 0 && dy >= 0) {
angle += 90.0;
} else if (dx <= 0 && dy <= 0) {
angle = 450.0 - angle;
}
for (int i = 0; i < (sortedStops.size() - 1); i++) {
if (angle >= (sortedStops.get(i).getOffset() * 360) && angle < (sortedStops.get(i + 1).getOffset() * 360)) {
double fraction = (angle - sortedStops.get(i).getOffset() * 360) / ((sortedStops.get(i + 1).getOffset() - sortedStops.get(i).getOffset()) * 360);
color = (Color) Interpolator.LINEAR.interpolate(sortedStops.get(i).getColor(), sortedStops.get(i + 1).getColor(), fraction);
}
}
PIXEL_WRITER.setColor(x, y, color);
}
}
return RASTER;
}
use of javafx.scene.image.WritableImage in project Board-Instrumentation-Framework by intel.
the class LcdSkin method createNoiseImage.
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;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
final Color NOISE_COLOR = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
final double NOISE_ALPHA = getSkinnable().clamp(0, 1, 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;
}
use of javafx.scene.image.WritableImage 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.WritableImage 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;
}
Aggregations