Search in sources :

Example 1 with ARGBScreenImage

use of net.imglib2.display.screenimage.awt.ARGBScreenImage in project imagej-ui-swing by imagej.

the class JHotDrawImageCanvas method capture.

/**
 * Captures the current view of data displayed in the canvas, including all
 * JHotDraw embellishments.
 */
public Dataset capture() {
    final ImageDisplay display = getDisplay();
    if (display == null)
        return null;
    final DatasetView datasetView = imageDisplayService.getActiveDatasetView(display);
    if (datasetView == null)
        return null;
    final ARGBScreenImage screenImage = datasetView.getScreenImage();
    final Image pixels = screenImage.image();
    final int w = pixels.getWidth(null);
    final int h = pixels.getHeight(null);
    // draw the backdrop image info
    final BufferedImage outputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D outputGraphics = outputImage.createGraphics();
    outputGraphics.drawImage(pixels, 0, 0, null);
    // draw the overlay info
    for (final FigureView view : figureViews) {
        view.getFigure().draw(outputGraphics);
    }
    // create a dataset that has view data with overlay info on top
    final Dataset dataset = datasetService.create(new long[] { w, h, 3 }, "Captured view", new AxisType[] { Axes.X, Axes.Y, Axes.CHANNEL }, 8, false, false);
    dataset.setRGBMerged(true);
    final RandomAccess<? extends RealType<?>> accessor = dataset.randomAccess();
    for (int x = 0; x < w; x++) {
        accessor.setPosition(x, 0);
        for (int y = 0; y < h; y++) {
            accessor.setPosition(y, 1);
            final int rgb = outputImage.getRGB(x, y);
            final int r = (rgb >> 16) & 0xff;
            final int g = (rgb >> 8) & 0xff;
            final int b = (rgb >> 0) & 0xff;
            accessor.setPosition(0, 2);
            accessor.get().setReal(r);
            accessor.setPosition(1, 2);
            accessor.get().setReal(g);
            accessor.setPosition(2, 2);
            accessor.get().setReal(b);
        }
    }
    return dataset;
}
Also used : ARGBScreenImage(net.imglib2.display.screenimage.awt.ARGBScreenImage) DatasetView(net.imagej.display.DatasetView) Dataset(net.imagej.Dataset) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) ARGBScreenImage(net.imglib2.display.screenimage.awt.ARGBScreenImage) ImageDisplay(net.imagej.display.ImageDisplay) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 2 with ARGBScreenImage

use of net.imglib2.display.screenimage.awt.ARGBScreenImage in project flimj-ui by flimlib.

the class PreviewImageDisplay method setImage.

/**
 * Shows an float-valued image, colored by a converter and possibly annotated by a annotator. If
 * either of the first two arguments are <code>null</code>, the display will show the
 * {@link #PLACEHOLDER_IMAGE}.
 *
 * @param src       The source image
 * @param converter The LUT converter
 * @param annotator The post-conversion processor functional
 */
public void setImage(final RandomAccessibleInterval<FloatType> src, final RealLUTConverter<FloatType> converter, final ImageAnnotator annotator) {
    rawImage = src;
    final int oldW = imgW;
    final int oldH = imgH;
    if (src != null && converter != null) {
        imgW = (int) src.dimension(0);
        imgH = (int) src.dimension(1);
    } else {
        imgW = (int) PLACEHOLDER_IMAGE.getWidth();
        imgH = (int) PLACEHOLDER_IMAGE.getHeight();
    }
    // reallocate buffers
    if (oldW != imgW || oldH != imgH)
        screenImage = new ARGBScreenImage(imgW, imgH);
    if (src != null && converter != null) {
        coloredImage = Converters.convert(src, converter, new ARGBType());
        // convert and annotate image
        Cursor<ARGBType> dstCsr = screenImage.localizingCursor();
        RandomAccess<ARGBType> lutedRA = coloredImage.randomAccess();
        RandomAccess<FloatType> valRA = src.randomAccess();
        while (dstCsr.hasNext()) {
            dstCsr.fwd();
            lutedRA.setPosition(dstCsr);
            valRA.setPosition(dstCsr);
            dstCsr.get().set(// 
            annotator != null ? annotator.annotate(valRA, lutedRA) : lutedRA.get());
        }
        view.setOpacity(1);
        clickPane.setVisible(true);
        cursor.setVisible(true);
    } else {
        // show placeholder
        SwingFXUtils.fromFXImage(PLACEHOLDER_IMAGE, screenImage.image());
        view.setOpacity(0.3);
        clickPane.setVisible(false);
        cursor.setVisible(false);
    }
    // resize with parent
    Bounds parentBounds = view.getParent().getLayoutBounds();
    fitSize(parentBounds.getWidth() - 10, parentBounds.getHeight() - 10);
    // force update as content may change
    lastReloadPixScale = Double.MIN_VALUE;
    reloadImageIfNecessary();
}
Also used : ARGBScreenImage(net.imglib2.display.screenimage.awt.ARGBScreenImage) Bounds(javafx.geometry.Bounds) ARGBType(net.imglib2.type.numeric.ARGBType) FloatType(net.imglib2.type.numeric.real.FloatType)

Aggregations

ARGBScreenImage (net.imglib2.display.screenimage.awt.ARGBScreenImage)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 Bounds (javafx.geometry.Bounds)1 Dataset (net.imagej.Dataset)1 DatasetView (net.imagej.display.DatasetView)1 ImageDisplay (net.imagej.display.ImageDisplay)1 ARGBType (net.imglib2.type.numeric.ARGBType)1 FloatType (net.imglib2.type.numeric.real.FloatType)1