Java Code Examples for javafx.scene.paint.Color#getRed()

The following examples show how to use javafx.scene.paint.Color#getRed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Font.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
private static void initalize() {
    initialized = true;
    font = new int[256][8];
    Thread fontLoader = new Thread(() -> {
        InputStream in = Font.class.getClassLoader().getResourceAsStream("jace/data/font.png");
        Image image = new Image(in);
        PixelReader reader = image.getPixelReader();
        for (int i = 0; i < 256; i++) {
            int x = (i >> 4) * 13 + 2;
            int y = (i & 15) * 13 + 4;
            for (int j = 0; j < 8; j++) {
                int row = 0;
                for (int k = 0; k < 7; k++) {
                    Color color = reader.getColor((7 - k) + x, j + y);
                    boolean on = color.getRed() != 0;
                    row = (row << 1) | (on ? 0 : 1);
                }
                font[i][j] = row;
            }
        }
    });
    fontLoader.start();
}
 
Example 2
Source File: Helper.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public static final double colorDistance(final Color COLOR_1, final Color COLOR_2) {
    final double DELTA_R = (COLOR_2.getRed()   - COLOR_1.getRed());
    final double DELTA_G = (COLOR_2.getGreen() - COLOR_1.getGreen());
    final double DELTA_B = (COLOR_2.getBlue()  - COLOR_1.getBlue());

    return Math.sqrt(DELTA_R * DELTA_R + DELTA_G * DELTA_G + DELTA_B * DELTA_B);
}
 
Example 3
Source File: JFXUtil.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Convert JFX color into model color
 *  @param color {@link Color}
 *  @return {@link WidgetColor}
 */
public static WidgetColor convert(final Color color)
{
    return new WidgetColor((int) (color.getRed() * 255),
                           (int) (color.getGreen() * 255),
                           (int) (color.getBlue() * 255),
                           (int) (color.getOpacity() * 255));
}
 
Example 4
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieve an overlay image.
 *
 * @param overlayType
 *            The overlay type.
 * @param side
 *            The side of the eye.
 * @param color
 *            The overlay color.
 *
 * @return The overlay image.
 */
private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color) {
	URL imageUrl = ClassLoader.getSystemResource("overlay/" + getOverlayFileName(overlayType, side));

	Image image = new Image(imageUrl.toExternalForm());

	Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE);
	Color colorNoAlpha = new Color(color.getRed(), color.getGreen(), color.getBlue(), 1);

	Blend effect = new Blend(
			BlendMode.SRC_ATOP,
			null,
			new ColorInput(
					0,
					0,
					OVERLAY_SIZE,
					OVERLAY_SIZE,
					colorNoAlpha));

	// Type 2 is not changed in color.
	if (overlayType != 2) {
		canvas.getGraphicsContext2D().setEffect(effect);
	}
	canvas.getGraphicsContext2D().setGlobalAlpha(color.getOpacity());
	canvas.getGraphicsContext2D().drawImage(image, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE);
	SnapshotParameters parameters = new SnapshotParameters();
	parameters.setFill(Color.TRANSPARENT);

	return canvas.snapshot(parameters, null);
}
 
Example 5
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to convert a color in linear RGB space to SRGB space.
 */
public static Color convertLinearRGBtoSRGB(Color color) {
    double[] colors = new double[] { color.getRed(), color.getGreen(), color.getBlue() };
    for (int i=0; i<colors.length; i++) {
        if (colors[i] <= 0.0031308) {
            colors[i] = colors[i] * 12.92;
        } else {
            colors[i] = (1.055 * Math.pow(colors[i], (1.0 / 2.4))) - 0.055;
        }
    }
    return Color.color(colors[0], colors[1], colors[2], color.getOpacity());
}
 
Example 6
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to convert a color in sRGB space to linear RGB space.
 */
public static Color convertSRGBtoLinearRGB(Color color) {
    double[] colors = new double[] { color.getRed(), color.getGreen(), color.getBlue() };
    for (int i=0; i<colors.length; i++) {
        if (colors[i] <= 0.04045) {
            colors[i] = colors[i] / 12.92;
        } else {
            colors[i] = Math.pow((colors[i] + 0.055) / 1.055, 2.4);
        }
    }
    return Color.color(colors[0], colors[1], colors[2], color.getOpacity());
}
 
Example 7
Source File: FxmlColor.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static double[] toDouble(Color color) {
    double[] srgb = new double[3];
    srgb[0] = color.getRed();
    srgb[1] = color.getGreen();
    srgb[2] = color.getBlue();
    return srgb;
}
 
Example 8
Source File: FxmlColor.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static float[] toFloat(Color color) {
    float[] srgb = new float[3];
    srgb[0] = (float) color.getRed();
    srgb[1] = (float) color.getGreen();
    srgb[2] = (float) color.getBlue();
    return srgb;
}
 
Example 9
Source File: JFXColorPickerUI.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private void setColorAtLocation(int x, int y) {
    if (allowColorChange) {
        Color color = getColorAtLocation(x, y);
        String colorString = "rgb(" + color.getRed() * 255 + "," + color.getGreen() * 255 + "," + color.getBlue() * 255 + ");";
        for (Node node : colorNodes)
            node.setStyle("-fx-background-color:" + colorString + "; -fx-fill:" + colorString+";");
    }
}
 
Example 10
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static java.awt.Color toAwtColor(Color color) {
    java.awt.Color newColor = new java.awt.Color((int) (color.getRed() * 255),
            (int) (color.getGreen() * 255),
            (int) (color.getBlue() * 255),
            (int) (color.getOpacity() * 255));
    return newColor;
}
 
Example 11
Source File: ColorUtilty.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *
 * @param color JavaFX color
 * @return AWT color
 */
@Nullable
public static java.awt.Color colorToAWTColor(final Color color)
{
	if (color == null)
	{
		return null;
	}
	return new java.awt.Color(
			(int) (color.getRed() * 255),
			(int) (color.getGreen() * 255),
			(int) (color.getBlue() * 255)
	);
}
 
Example 12
Source File: Hash.java    From JImageHash with MIT License 5 votes vote down vote up
/**
 * Creates a visual representation of the hash mapping the hash values to the
 * section of the rescaled image used to generate the hash.
 * 
 * @param bitColorIndex array mapping each bit of the hash to a color of the
 *                      color array
 * @param colors        array to colorize the pixels
 * @param blockSize     scaling factor of each pixel in the has. each bit of the
 *                      hash will be represented to blockSize*blockSize pixels
 * @return A colorized image representing the individual bits of the hash
 */
public BufferedImage toImage(int[] bitColorIndex, Color[] colors, int blockSize) {
	int width = (int) Math.sqrt(hashLength);
	int height = width;

	BufferedImage bi = new BufferedImage(blockSize * width, blockSize * height, BufferedImage.TYPE_3BYTE_BGR);

	FastPixel fp = FastPixel.create(bi);

	int i = 0;
	for (int w = 0; w < width * blockSize; w = w + blockSize) {
		for (int h = 0; h < height * blockSize; h = h + blockSize) {
			Color c = colors[bitColorIndex[i++]];
			int red = (int) (c.getRed() * 255);
			int green = (int) (c.getGreen() * 255);
			int blue = (int) (c.getBlue() * 255);

			for (int m = 0; m < blockSize; m++) {
				for (int n = 0; n < blockSize; n++) {
					int x = w + m;
					int y = h + n;
					// bi.setRGB(y, x, bit ? black : white);
					// fp.setAverageGrayscale(x, y, gray);
					fp.setRed(x, y, red);
					fp.setGreen(x, y, green);
					fp.setBlue(x, y, blue);
				}
			}
		}
	}
	return bi;
}
 
Example 13
Source File: Util.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public static Image createGrayNoise(final double WIDTH, final double HEIGHT, final Color COLOR, final int VARIATION) {
    int red   = (int) (255 * COLOR.getRed());
    int green = (int) (255 * COLOR.getRed());
    int blue  = (int) (255 * COLOR.getRed());
    int variation = clamp(0, 255, VARIATION) / 2;
    Color darkColor   = Color.rgb(clamp(0, 255, red - variation), clamp(0, 255, green - variation), clamp(0, 255, blue - variation));
    Color brightColor = Color.rgb(clamp(0, 255, red + variation), clamp(0, 255, green + variation), clamp(0, 255, blue + variation));
    return createGrayNoise(WIDTH, HEIGHT, darkColor, brightColor);
}
 
Example 14
Source File: ColorPickerSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private String createRGBString(Color c) {
    return "-fx-base: rgb(" + (c.getRed() * 255) + "," + (c.getGreen() * 255) + "," + (c.getBlue() * 255) + ");";
}
 
Example 15
Source File: SVColorIntArray.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorIntArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 16
Source File: EggView.java    From narjillos with MIT License 4 votes vote down vote up
private Color getFillColor(boolean infraredOn) {
	Color color = (infraredOn ? Color.RED : Color.BURLYWOOD);
	return new Color(color.getRed(), color.getGreen(), color.getBlue(), getOpacity());
}
 
Example 17
Source File: FxmlColor.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static String rgb2css(Color color) {
    return "rgba(" + (int) (color.getRed() * 255) + ","
            + (int) (color.getGreen() * 255) + ","
            + (int) (color.getBlue() * 255) + ","
            + color.getOpacity() + ")";
}
 
Example 18
Source File: ImageEditingApp.java    From FXTutorials with MIT License 4 votes vote down vote up
private double valueOf(Color c) {
    return c.getRed() + c.getGreen() + c.getBlue();
}
 
Example 19
Source File: SVColorArray.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 20
Source File: ColorGradientAxis.java    From chart-fx with Apache License 2.0 2 votes vote down vote up
/**
 * Return the color for a value as an integer with the color values in its bytes. For use e.g. with an IntBuffer
 * backed PixelBuffer.
 * 
 * @param value z-Value
 * @return integer with one byte each set to alpha, red, green, blue
 */
public int getIntColor(final double value) {
    final Color color = getColor(value);
    return ((byte) (color.getOpacity() * 255) << 24) + ((byte) (color.getRed() * 255) << 16)
            + ((byte) (color.getGreen() * 255) << 8) + ((byte) (color.getBlue() * 255));
}