List of usage examples for javafx.embed.swing SwingFXUtils toFXImage
public static WritableImage toFXImage(BufferedImage bimg, WritableImage wimg)
From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java
/** * Pre-cache the next set of images and calculate if necessary * @param pRecord/* w w w . ja v a2s . co m*/ */ private void internalPrecachePair(final int pRecord) { if (pRecord >= gResults.size()) { gLogger.trace("Precache: No next!"); return; } if (pRecord < 0) { gLogger.trace("Precache: No prev!"); return; } gLogger.trace("Precaching record: " + pRecord); gArePrecachingNow = true; boolean justLoad = false; if (!gResults.get(pRecord).processed) { if (gResults.get(pRecord).claimForProcessing()) { List<CheckResult> single = new LinkedList<CheckResult>(); single.add(gResults.get(pRecord)); Task<Integer> task = new ProcessingLoadTask(single, false, true, true); Thread loader = new Thread(task); loader.setDaemon(true); //FIXME: hack here to set precached id gPrecached = pRecord; loader.start(); return; } else { //enter busy-wait loop? - just load images and presume calcs will be done(?) justLoad = true; } } if (gResults.get(pRecord).processed | justLoad) { Task<Integer> task = new Task<Integer>() { @Override protected Integer call() throws Exception { gLogger.trace("just loading images for precache (no calcs)"); final Image left = SwingFXUtils.toFXImage(internalLoadImage(gResults.get(pRecord).getFileOne()), null); final Image right = SwingFXUtils .toFXImage(internalLoadImage(gResults.get(pRecord).getFileTwo()), null); Platform.runLater(new Runnable() { //@Override public void run() { gPrecachedLeft = left; gPrecachedRight = right; gPrecached = pRecord; gArePrecachingNow = false; } }); gLogger.trace("Precaching done for record " + pRecord); return null; } }; Thread loader = new Thread(task); loader.setDaemon(true); loader.start(); return; } gLogger.trace("Precaching incomplete for record " + pRecord); gArePrecachingNow = false; gPrecached = -1; }
From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java
/** * Reload a record (no calculations)// w ww . j a v a 2 s. co m * @param pRecord */ private void internalReloadRecord(final int pRecord) { gLogger.trace("Reloading record: " + pRecord); Task<Integer> task = new Task<Integer>() { @Override protected Integer call() throws Exception { int max = 2; int count = 0; Platform.runLater(new Runnable() { //@Override public void run() { internalBeforeGUIThread(); imageLeft.setImage(null); imageRight.setImage(null); imageLeftLabel.setText(gResults.get(pRecord).getFileOne().getName()); imageRightLabel.setText(gResults.get(pRecord).getFileTwo().getName()); psnrLabelValue.setText(gResults.get(pRecord).getPsnr() + ""); ssimLabelValue.setText(gResults.get(pRecord).getSsimMean() + ""); internalSetSSIMVariance(gResults.get(pRecord).getSsimVariance()); ssimMinValue.setText(gResults.get(pRecord).getSsimMin() + ""); internalUpdateManualCheckLabel(pRecord); } }); final BufferedImage one = internalLoadImage(gResults.get(pRecord).getFileOne()); Platform.runLater(new Runnable() { //@Override public void run() { imageLeft.setImage(SwingFXUtils.toFXImage(one, null)); } }); updateProgress(++count, max); final BufferedImage two = internalLoadImage(gResults.get(pRecord).getFileTwo()); Platform.runLater(new Runnable() { //@Override public void run() { imageRight.setImage(SwingFXUtils.toFXImage(two, null)); internalImageZoomToFit(); } }); updateProgress(++count, max); internalAfterGUIThread(); return null; } }; progressIndicator.progressProperty().bind(task.progressProperty()); Thread loader = new Thread(task); loader.setDaemon(true); loader.start(); internalDisableInterface(false); }
From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java
/** * overlay heatmap on image//from ww w. j a v a 2 s. com */ private void internalOverlayHeatmap() { gRightImageSave = imageRight.getImage(); if (!gHeatmapGenerated) { internalBeforeGUIThread(); //threaded load so GUI doesn't hang Task<Integer> task = new Task<Integer>() { @Override protected Integer call() throws Exception { BufferedImage image = SwingFXUtils.fromFXImage(imageRight.getImage(), null); if (gHeatmap == null) { //re-generate heatmap (must be on a re-load) try { gHeatmap = Imaging.getBufferedImage(gResults.get(gCurrentRecord).getHeatmapTemp()); } catch (IOException | ImageReadException e) { // TODO Auto-generated catch block e.printStackTrace(); } } for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int rgb = image.getRGB(x, y); Color heatmapColor = new Color(gHeatmap.getRGB((x / DissimilarV2.SSIMWINDOWSIZE), (y / DissimilarV2.SSIMWINDOWSIZE))); int heatmapPixel = heatmapColor.getGreen();//&maxPixelValue; if (heatmapColor.getGreen() != heatmapColor.getBlue() && heatmapColor.getBlue() != heatmapColor.getRed()) { gLogger.error("Heatmap error (should not happen)"); } double factor = 1 - (((double) heatmapPixel / 255)); Color col = new Color(rgb); int red = (int) (factor * col.getRed()); int green = (int) (factor * col.getGreen()); int blue = (int) (factor * col.getBlue()); if (red < 0) red = 0; if (green < 0) green = 0; if (blue < 0) blue = 0; col = new Color(red, green, blue); image.setRGB(x, y, col.getRGB()); } } gHeatmapImage = SwingFXUtils.toFXImage(image, null); gHeatmapGenerated = true; Platform.runLater(new Runnable() { //@Override public void run() { imageRight.setImage(gHeatmapImage); } }); internalAfterGUIThread(); return 1; } }; progressIndicator.progressProperty().bind(task.progressProperty()); Thread loader = new Thread(task); loader.setDaemon(true); loader.start(); } else { imageRight.setImage(gHeatmapImage); } }