javafx.scene.image.PixelWriter Java Examples
The following examples show how to use
javafx.scene.image.PixelWriter.
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: WriteFxImage.java From chart-fx with Apache License 2.0 | 7 votes |
/** * copy the given Image to a WritableImage * * @param image the input image * @return clone of image */ public static WritableImage clone(Image image) { int height = (int) image.getHeight(); int width = (int) image.getWidth(); WritableImage writableImage = WritableImageCache.getInstance().getImage(width, height); PixelWriter pixelWriter = writableImage.getPixelWriter(); if (pixelWriter == null) { throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE); } final PixelReader pixelReader = image.getPixelReader(); if (pixelReader == null) { throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE); } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Color color = pixelReader.getColor(x, y); pixelWriter.setColor(x, y, color); } } return writableImage; }
Example #2
Source File: FXColorPicker.java From gef with Eclipse Public License 2.0 | 7 votes |
/** * Draws a color wheel into the given {@link WritableImage}, starting at the * given offsets, in the given size (in pixel). * * @param image * The {@link WritableImage} in which the color wheel is drawn. * @param offsetX * The horizontal offset (in pixel). * @param offsetY * The vertical offset (in pixel). * @param size * The size (in pixel). */ private void renderColorWheel(WritableImage image, int offsetX, int offsetY, int size) { PixelWriter px = image.getPixelWriter(); double radius = size / 2; Point2D mid = new Point2D(radius, radius); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { double d = mid.distance(x, y); if (d <= radius) { // compute hue angle double angleRad = d == 0 ? 0 : Math.atan2(y - mid.getY(), x - mid.getX()); // compute saturation depending on distance to // middle // ([0;1]) double sat = d / radius; Color color = Color.hsb(angleRad * 180 / Math.PI, sat, 1); px.setColor(offsetX + x, offsetY + y, color); } else { px.setColor(offsetX + x, offsetY + y, Color.TRANSPARENT); } } } }
Example #3
Source File: ImageOperatorSample.java From marathonv5 with Apache License 2.0 | 6 votes |
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) { PixelWriter pw = img.getPixelWriter(); double w = img.getWidth(); double h = img.getHeight(); double xRatio = 0.0; double yRatio = 0.0; double hue = 0.0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { xRatio = x/w; yRatio = y/h; hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset; Color c = Color.hsb(hue, 1.0, 1.0); pw.setColor(x, y, c); } } }
Example #4
Source File: ViewText.java From latexdraw with GNU General Public License v3.0 | 6 votes |
/** * Adds transparency to the given image. * @param img The image to transform. * @return The same image with white replaced by transparent. */ private WritableImage toTransparentPNG(final Image img) { final PixelReader pixelReader = img.getPixelReader(); final WritableImage wImage = new WritableImage((int) img.getWidth(), (int) img.getHeight()); final PixelWriter pixelWriter = wImage.getPixelWriter(); for(int readY = 0; readY < img.getHeight(); readY++) { for(int readX = 0; readX < img.getWidth(); readX++) { final javafx.scene.paint.Color color = pixelReader.getColor(readX, readY); if (color.equals(javafx.scene.paint.Color.WHITE)) { pixelWriter.setColor(readX, readY, new javafx.scene.paint.Color(color.getRed(), color.getGreen(), color.getBlue(), 0)); // new javafx.scene.paint.Color(1, 1, 1, 0)); } else { pixelWriter.setColor(readX, readY, color); } } } return wImage; }
Example #5
Source File: ImageOperatorSample.java From marathonv5 with Apache License 2.0 | 6 votes |
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) { PixelWriter pw = img.getPixelWriter(); double w = img.getWidth(); double h = img.getHeight(); double xRatio = 0.0; double yRatio = 0.0; double hue = 0.0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { xRatio = x/w; yRatio = y/h; hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset; Color c = Color.hsb(hue, 1.0, 1.0); pw.setColor(x, y, c); } } }
Example #6
Source File: ColorMapDialog.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Update color bar in UI from current 'map' */ private void updateColorBar() { // On Mac OS X it was OK to create an image sized 256 x 1: // 256 wide to easily set the 256 colors, // 1 pixel height which is then stretched via the BackgroundSize(). // On Linux, the result was garbled unless the image height matched the // actual height, so it's now fixed to COLOR_BAR_HEIGHT final WritableImage colors = new WritableImage(256, COLOR_BAR_HEIGHT); final PixelWriter writer = colors.getPixelWriter(); for (int x=0; x<256; ++x) { final int arfb = ColorMappingFunction.getRGB(map.getColor(x)); for (int y=0; y<COLOR_BAR_HEIGHT; ++y) writer.setArgb(x, y, arfb); } // Stretch image to fill color_bar color_bar.setBackground(new Background( new BackgroundImage(colors, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true)))); }
Example #7
Source File: ImageScaling.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override public void start(final Stage stage) { // Image with red border final WritableImage image = new WritableImage(WIDTH, HEIGHT); final PixelWriter writer = image.getPixelWriter(); for (int x=0; x<WIDTH; ++x) { writer.setColor(x, 0, Color.RED); writer.setColor(x, HEIGHT-1, Color.RED); } for (int y=0; y<HEIGHT; ++y) { writer.setColor(0, y, Color.RED); writer.setColor(WIDTH-1, y, Color.RED); } // Draw into canvas, scaling 'up' final Canvas canvas = new Canvas(800, 600); canvas.getGraphicsContext2D().drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight()); final Scene scene = new Scene(new Group(canvas), canvas.getWidth(), canvas.getHeight()); stage.setScene(scene); stage.show(); }
Example #8
Source File: HeatMap.java From charts with Apache License 2.0 | 6 votes |
/** * Recreates the heatmap based on the current monochrome map. * Using this approach makes it easy to change the used color * mapping. */ private void updateHeatMap() { monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage); int width = monochromeImage.widthProperty().intValue(); int height = monochromeImage.heightProperty().intValue(); heatMap = new WritableImage(width, height); Color colorFromMonoChromeImage; double brightness; Color mappedColor; PixelWriter pixelWriter = heatMap.getPixelWriter(); PixelReader pixelReader = monochromeImage.getPixelReader(); for (int y = 0 ; y < height ; y++) { for (int x = 0 ; x < width ; x++) { colorFromMonoChromeImage = pixelReader.getColor(x, y); brightness = colorFromMonoChromeImage.getOpacity(); mappedColor = Helper.getColorAt(mappingGradient, brightness); pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor); } } setImage(heatMap); }
Example #9
Source File: SingleColorTextureFileCreator.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread protected boolean validate(@NotNull final VarTable vars) { final Color color = UiUtils.from(vars.get(PROP_COLOR, ColorRGBA.class)); final int width = vars.getInteger(PROP_WIDTH); final int height = vars.getInteger(PROP_HEIGHT); final WritableImage writableImage = new WritableImage(width, height); final PixelWriter pixelWriter = writableImage.getPixelWriter(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { pixelWriter.setColor(i, j, color); } } getImageView().setImage(writableImage); return true; }
Example #10
Source File: SingleColorTextureFileCreator.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @BackgroundThread protected void writeData(@NotNull final VarTable vars, final @NotNull Path resultFile) throws IOException { super.writeData(vars, resultFile); final Color color = UiUtils.from(vars.get(PROP_COLOR, ColorRGBA.class)); final int width = vars.getInteger(PROP_WIDTH); final int height = vars.getInteger(PROP_HEIGHT); final WritableImage writableImage = new WritableImage(width, height); final PixelWriter pixelWriter = writableImage.getPixelWriter(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { pixelWriter.setColor(i, j, color); } } final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(writableImage, null); try (final OutputStream out = Files.newOutputStream(resultFile)) { ImageIO.write(bufferedImage, "png", out); } }
Example #11
Source File: Helper.java From Medusa with Apache License 2.0 | 6 votes |
public static final Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) { if (Double.compare(WIDTH, 0) <= 0 || Double.compare(HEIGHT, 0) <= 0) return null; int width = (int) WIDTH; int height = (int) HEIGHT; double alphaVariationInPercent = Helper.clamp(0.0, 100.0, 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() ? BRIGHT_COLOR : DARK_COLOR; final double NOISE_ALPHA = Helper.clamp(0.0, 1.0, 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; }
Example #12
Source File: JFXColorPickerUI.java From JFoenix with Apache License 2.0 | 6 votes |
private Image getHuesCircle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); double rsmall = 0.8 * width / 2; double rbig = (double) width / 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)); double o = Math.atan2(dy, dx); if (distance > rsmall && distance < rbig) { double H = map(o, -Math.PI, Math.PI, 0, 255); double S = 255; double L = 152; pixelWriter.setColor(x, y, HSL2RGB(H, S, L)); } } } return raster; }
Example #13
Source File: BasicEncoder.java From FXTutorials with MIT License | 6 votes |
@Override public Image encode(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 = encode(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; }
Example #14
Source File: Palette.java From FXyzLib with GNU General Public License v3.0 | 6 votes |
public Image createPalette(boolean save){ if(numColors<1){ return null; } // try to create a square image width=(int)Math.sqrt(numColors); height=numColors/width; imgPalette = new WritableImage(width, height); PixelWriter pw = ((WritableImage)imgPalette).getPixelWriter(); AtomicInteger count = new AtomicInteger(); IntStream.range(0, height).boxed() .forEach(y->IntStream.range(0, width).boxed() .forEach(x->pw.setColor(x, y, getColor(count.getAndIncrement())))); if(save){ saveImage(); } return imgPalette; }
Example #15
Source File: VideoDHGR.java From jace with GNU General Public License v2.0 | 6 votes |
protected void displayLores(WritableImage screen, int xOffset, int y, int rowAddress) { int c1 = ((RAM128k) computer.getMemory()).getMainMemory().readByte(rowAddress + xOffset) & 0x0FF; if ((y & 7) < 4) { c1 &= 15; } else { c1 >>= 4; } Color color = Palette.color[c1]; // Unrolled loop, faster PixelWriter writer = screen.getPixelWriter(); int xx = xOffset * 14; writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); }
Example #16
Source File: VideoDHGR.java From jace with GNU General Public License v2.0 | 6 votes |
protected void showDhgr(WritableImage screen, int xOffset, int y, int dhgrWord) { PixelWriter writer = screen.getPixelWriter(); try { for (int i = 0; i < 7; i++) { Color color; if (!dhgrMode && hiresMode) { color = Palette.color[dhgrWord & 15]; } else { color = Palette.color[FLIP_NYBBLE[dhgrWord & 15]]; } writer.setColor(xOffset++, y, color); writer.setColor(xOffset++, y, color); writer.setColor(xOffset++, y, color); writer.setColor(xOffset++, y, color); dhgrWord >>= 4; } } catch (ArrayIndexOutOfBoundsException ex) { Logger.getLogger(getClass().getName()).warning("Went out of bounds in video display"); } }
Example #17
Source File: VideoDHGR.java From jace with GNU General Public License v2.0 | 6 votes |
protected void showBW(WritableImage screen, int xOffset, int y, int dhgrWord) { // Using the data buffer directly is about 15 times faster than setRGB // This is because setRGB does extra (useless) color model logic // For that matter even Graphics.drawLine is faster than setRGB! // This is equivilant to y*560 but is 5% faster // Also, adding xOffset now makes it additionally 5% faster //int yOffset = ((y << 4) + (y << 5) + (y << 9))+xOffset; int xx = xOffset; PixelWriter writer = screen.getPixelWriter(); for (int i = 0; i < 28; i++) { if (xx < 560) { // yOffset++ is used instead of yOffset+i, because it is faster writer.setColor(xx++, y, (dhgrWord & 1) == 1 ? WHITE : BLACK); } dhgrWord >>= 1; } }
Example #18
Source File: LcdSkin.java From Enzo with Apache License 2.0 | 6 votes |
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; Color noiseColor; double noiseAlpha; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR; noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION); PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha)); } } return IMAGE; }
Example #19
Source File: LcdClockSkin.java From Enzo with Apache License 2.0 | 6 votes |
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; Color noiseColor; double noiseAlpha; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR; noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION); PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha)); } } return IMAGE; }
Example #20
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 6 votes |
public static Image horizontalImage(Image image) { int width = (int) image.getWidth(); int height = (int) image.getHeight(); PixelReader pixelReader = image.getPixelReader(); WritableImage newImage = new WritableImage(width, height); PixelWriter pixelWriter = newImage.getPixelWriter(); for (int j = 0; j < height; ++j) { int l = 0, r = width - 1; while (l <= r) { Color cl = pixelReader.getColor(l, j); Color cr = pixelReader.getColor(r, j); pixelWriter.setColor(l, j, cr); pixelWriter.setColor(r, j, cl); l++; r--; } } return newImage; }
Example #21
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 6 votes |
public static Image verticalImage(Image image) { int width = (int) image.getWidth(); int height = (int) image.getHeight(); PixelReader pixelReader = image.getPixelReader(); WritableImage newImage = new WritableImage(width, height); PixelWriter pixelWriter = newImage.getPixelWriter(); for (int i = 0; i < width; ++i) { int t = 0, b = height - 1; while (t <= b) { Color ct = pixelReader.getColor(i, t); Color cb = pixelReader.getColor(i, b); pixelWriter.setColor(i, t, cb); pixelWriter.setColor(i, b, ct); t++; b--; } } return newImage; }
Example #22
Source File: HeadImagePanel.java From oim-fx with MIT License | 6 votes |
private void setGrayImage(Image image) { if (null != image && !image.isBackgroundLoading()) { int imageWidth = (int) image.getWidth(); int imageHeight = (int) image.getHeight(); if (imageWidth > 0 && imageHeight > 0) { PixelReader pixelReader = image.getPixelReader(); grayImage = new WritableImage(imageWidth, imageHeight); PixelWriter pixelWriter = grayImage.getPixelWriter(); if (null != pixelWriter && null != pixelReader) { for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { Color color = pixelReader.getColor(x, y); color = color.grayscale(); pixelWriter.setColor(x, y, color); } } } } else { grayImage = null; } } else { grayImage = null; } }
Example #23
Source File: HeadImageItemPane.java From oim-fx with MIT License | 6 votes |
private void setGrayImage(Image image) { if (null != image&&!image.isBackgroundLoading()) { int imageWidth = (int) image.getWidth(); int imageHeight = (int) image.getHeight(); if (imageWidth > 0 && imageHeight > 0) { PixelReader pixelReader = image.getPixelReader(); grayImage = new WritableImage(imageWidth, imageHeight); PixelWriter pixelWriter = grayImage.getPixelWriter(); for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { Color color = pixelReader.getColor(x, y); color = color.grayscale(); pixelWriter.setColor(x, y, color); } } } else { grayImage = null; } } else { grayImage = null; } }
Example #24
Source File: ImagePane.java From oim-fx with MIT License | 6 votes |
private void setGrayImage(Image image) { if (null != image && !image.isBackgroundLoading()) { int imageWidth = (int) image.getWidth(); int imageHeight = (int) image.getHeight(); if (imageWidth > 0 && imageHeight > 0) { PixelReader pixelReader = image.getPixelReader(); grayImage = new WritableImage(imageWidth, imageHeight); PixelWriter pixelWriter = grayImage.getPixelWriter(); for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { Color color = pixelReader.getColor(x, y); color = color.grayscale(); pixelWriter.setColor(x, y, color); } } } else { grayImage = null; } } else { grayImage = null; } }
Example #25
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 6 votes |
public static Image cropInsideFx(Image image, DoubleShape shape, Color bgColor) { if (image == null || shape == null || !shape.isValid() || bgColor == null) { return image; } int width = (int) image.getWidth(); int height = (int) image.getHeight(); PixelReader pixelReader = image.getPixelReader(); WritableImage newImage = new WritableImage(width, height); PixelWriter pixelWriter = newImage.getPixelWriter(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (shape.include(x, y)) { pixelWriter.setColor(x, y, bgColor); } else { pixelWriter.setColor(x, y, pixelReader.getColor(x, y)); } } } return newImage; }
Example #26
Source File: ContourDataSetCache.java From chart-fx with Apache License 2.0 | 5 votes |
protected WritableImage convertDataArrayToImage(final double[] inputData, final int dataWidth, final int dataHeight, final ColorGradient colorGradient) { final int length = dataWidth * dataHeight; final byte[] byteBuffer = ByteArrayCache.getInstance().getArrayExact(length * BGRA_BYTE_SIZE); final int rowSizeInBytes = BGRA_BYTE_SIZE * dataWidth; final WritableImage image = this.getImage(dataWidth, dataHeight); final PixelWriter pixelWriter = image.getPixelWriter(); if (pixelWriter == null) { if (LOGGER.isErrorEnabled()) { LOGGER.atError().log("Could not get PixelWriter for image"); } return image; } final int hMinus1 = dataHeight - 1; for (int yIndex = 0; yIndex < dataHeight; yIndex++) { final int rowIndex = dataWidth * yIndex; final int rowPixelIndex = rowSizeInBytes * (hMinus1 - yIndex); for (int xIndex = 0; xIndex < dataWidth; xIndex++) { final int x = xIndex; final int[] color = colorGradient.getColorBytes(inputData[rowIndex + xIndex]); final int pixelIndex = rowPixelIndex + x * BGRA_BYTE_SIZE; byteBuffer[pixelIndex] = (byte) (color[3]); byteBuffer[pixelIndex + 1] = (byte) (color[2]); byteBuffer[pixelIndex + 2] = (byte) (color[1]); byteBuffer[pixelIndex + 3] = (byte) (color[0]); } } pixelWriter.setPixels(0, 0, dataWidth, dataHeight, PixelFormat.getByteBgraPreInstance(), byteBuffer, 0, rowSizeInBytes); ByteArrayCache.getInstance().add(byteBuffer); return image; }
Example #27
Source File: Util.java From Enzo with Apache License 2.0 | 5 votes |
public static Image createGrayNoise(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR) { if (WIDTH <= 0 || HEIGHT <= 0) { return null; } final WritableImage IMAGE = new WritableImage((int) WIDTH, (int) HEIGHT); final PixelWriter PIXEL_WRITER = IMAGE.getPixelWriter(); final Random RND = new Random(); double redDark = DARK_COLOR.getRed(); double greenDark = DARK_COLOR.getGreen(); double blueDark = DARK_COLOR.getBlue(); double redBright = DARK_COLOR.getRed(); double greenBright = DARK_COLOR.getGreen(); double blueBright = DARK_COLOR.getBlue(); int startRed = (int) (Math.min(redDark, redBright) * 255); int startGreen = (int) (Math.min(greenDark, greenBright) * 255); int startBlue = (int) (Math.min(blueDark, blueBright) * 255); int start = returnLargest(startRed, startGreen, startBlue); int deltaRed = Math.abs((int) ((BRIGHT_COLOR.getRed() - DARK_COLOR.getRed()) * 255)); int deltaGreen = Math.abs((int) ((BRIGHT_COLOR.getGreen() - DARK_COLOR.getGreen()) * 255)); int deltaBlue = Math.abs((int) ((BRIGHT_COLOR.getBlue() - DARK_COLOR.getBlue()) * 255)); int delta = returnLargest(deltaRed, deltaGreen, deltaBlue); int gray; for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { gray = delta > 0 ? start + RND.nextInt(delta) : start; PIXEL_WRITER.setColor(x, y, Color.rgb(clamp(0, 255, gray), clamp(0, 255, gray), clamp(0, 255, gray))); } } return IMAGE; }
Example #28
Source File: VideoDHGR.java From jace with GNU General Public License v2.0 | 5 votes |
protected void displayDoubleLores(WritableImage screen, int xOffset, int y, int rowAddress) { int c1 = ((RAM128k) computer.getMemory()).getAuxVideoMemory().readByte(rowAddress + xOffset) & 0x0FF; int c2 = ((RAM128k) computer.getMemory()).getMainMemory().readByte(rowAddress + xOffset) & 0x0FF; if ((y & 7) < 4) { c1 &= 15; c2 &= 15; } else { c1 >>= 4; c2 >>= 4; } PixelWriter writer = screen.getPixelWriter(); // int yOffset = xyOffset[y][times14[xOffset]]; Color color = Palette.color[FLIP_NYBBLE[c1]]; // Unrolled loop, faster int xx = xOffset * 14; writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); color = Palette.color[c2]; writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); writer.setColor(xx++, y, color); }
Example #29
Source File: FindUserItem.java From oim-fx with MIT License | 5 votes |
private void setGrayImage(Image image) { PixelReader pixelReader = image.getPixelReader(); grayImage = new WritableImage((int) image.getWidth(), (int) image.getHeight()); PixelWriter pixelWriter = grayImage.getPixelWriter(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { Color color = pixelReader.getColor(x, y); color = color.grayscale(); pixelWriter.setColor(x, y, color); } } }
Example #30
Source File: JavaFXNES.java From halfnes with GNU General Public License v3.0 | 5 votes |
@Override public void setFrame(int[] nespixels, int[] bgcolor, boolean dotcrawl) { Platform.runLater(() -> { frametimes[frametimeptr] = nes.getFrameTime(); ++frametimeptr; frametimeptr %= frametimes.length; if (frametimeptr == 0) { long averageframes = 0; for (long l : frametimes) { averageframes += l; } averageframes /= frametimes.length; fps = 1E9 / averageframes; stage.setTitle(String.format("HalfNES %s, %2.2f fps", // + ((nes.frameskip > 0) ? " frameskip " + nes.frameskip : ""), NES.VERSION, // nes.getCurrentRomName(), fps)); } PixelWriter writer = gameCanvas.getGraphicsContext2D().getPixelWriter(); for (int i = 0; i < nespixels.length; i++) { byte[] colbytes = NesColors.colbytes[(nespixels[i] & 0x1c0) >> 6][nespixels[i] & 0x3f]; System.arraycopy(colbytes, 0, buffer, i * 4, 3); } writer.setPixels(0, 0, 256, 240, format, buffer, 0, 256 * 4); }); }