Search in sources :

Example 6 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project jdk8u_jdk by JetBrains.

the class CardinalTextField method calculateImage.

/**
     * Calculates and returns the image.  Halts the calculation and returns
     * null if the Applet is stopped during the calculation.
     */
private Image calculateImage() {
    Thread me = Thread.currentThread();
    int width = canvas.getSize().width;
    int height = canvas.getSize().height;
    int[] xvals = new int[2];
    int[] yvals = new int[2];
    int xmethod = XControls.getParams(xvals);
    int ymethod = YControls.getParams(yvals);
    int[] pixels = new int[width * height];
    //temporarily holds R,G,B,A information
    int[] c = new int[4];
    int index = 0;
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            c[0] = c[1] = c[2] = 0;
            c[3] = 255;
            if (xmethod < ymethod) {
                applyMethod(c, xmethod, i, width, xvals);
                applyMethod(c, ymethod, j, height, yvals);
            } else {
                applyMethod(c, ymethod, j, height, yvals);
                applyMethod(c, xmethod, i, width, xvals);
            }
            pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8) | c[2]);
        }
        // Poll once per row to see if we've been told to stop.
        if (runner != me) {
            return null;
        }
    }
    return createImage(new MemoryImageSource(width, height, ColorModel.getRGBdefault(), pixels, 0, width));
}
Also used : MemoryImageSource(java.awt.image.MemoryImageSource)

Example 7 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project jdk8u_jdk by JetBrains.

the class ImageSelection method createImage.

private static Image createImage() {
    int w = 100;
    int h = 100;
    int[] pix = new int[w * h];
    int index = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int red = 127;
            int green = 127;
            int blue = y > h / 2 ? 127 : 0;
            int alpha = 255;
            if (x < w / 4 && y < h / 4) {
                alpha = 0;
                red = 0;
            }
            pix[index++] = (alpha << 24) | (red << 16) | (green << 8) | blue;
        }
    }
    return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w));
}
Also used : MemoryImageSource(java.awt.image.MemoryImageSource)

Example 8 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project JMRI by JMRI.

the class NamedIcon method createRotatedImage.

/**
     * The following was based on a text-rotating applet from David Risner,
     * available at http://www.risner.org/java/rotate_text.html
     *
     * @param pImage     Image to transform
     * @param pComponent Component containing the image, needed to obtain a
     *                   MediaTracker to process the image consistently with
     *                   display
     * @param pRotation  0-3 number of 90-degree rotations needed
     * @return new Image object containing the rotated input image
     */
public Image createRotatedImage(Image pImage, Component pComponent, int pRotation) {
    if (log.isDebugEnabled()) {
        log.debug("createRotatedImage: pRotation= " + pRotation + ", mRotation= " + mRotation);
    }
    if (pRotation == 0) {
        return pImage;
    }
    MediaTracker mt = new MediaTracker(pComponent);
    mt.addImage(pImage, 0);
    try {
        mt.waitForAll();
    } catch (InterruptedException ie) {
        // retain if needed later
        Thread.currentThread().interrupt();
    }
    int w = pImage.getWidth(null);
    int h = pImage.getHeight(null);
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(pImage, 0, 0, w, h, pixels, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException ie) {
    }
    int[] newPixels = new int[w * h];
    // transform the pixels
    MemoryImageSource imageSource = null;
    switch(pRotation) {
        case // 90 degrees
        1:
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    newPixels[x * h + y] = pixels[y * w + (w - 1 - x)];
                }
            }
            imageSource = new MemoryImageSource(h, w, ColorModel.getRGBdefault(), newPixels, 0, h);
            break;
        case // 180 degrees
        2:
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    newPixels[x * h + y] = pixels[(w - 1 - x) * h + (h - 1 - y)];
                }
            }
            imageSource = new MemoryImageSource(w, h, ColorModel.getRGBdefault(), newPixels, 0, w);
            break;
        case // 270 degrees
        3:
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    newPixels[x * h + y] = pixels[(h - 1 - y) * w + x];
                }
            }
            imageSource = new MemoryImageSource(h, w, ColorModel.getRGBdefault(), newPixels, 0, h);
            break;
        default:
            log.warn("Unhandled rotation code: {}", pRotation);
            break;
    }
    Image myImage = pComponent.createImage(imageSource);
    mt.addImage(myImage, 1);
    try {
        mt.waitForAll();
    } catch (InterruptedException ie) {
    }
    return myImage;
}
Also used : MediaTracker(java.awt.MediaTracker) PixelGrabber(java.awt.image.PixelGrabber) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 9 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project vcell by virtualcell.

the class GeometrySummaryPanel method createIcon.

/**
 * Comment
 */
public javax.swing.Icon createIcon(VCImage sampledImage, Geometry geom) throws cbit.image.GifParsingException, ImageException {
    if (sampledImage == null) {
        return null;
    } else {
        VCImage sampledGeometryHandles = null;
        if (geom.getDimension() > 0) {
            // project and scale geometry
            int SAMPLED_GEOM_SIZE = 150;
            sampledGeometryHandles = cbit.image.DitherIndexImage.dither(sampledImage, SAMPLED_GEOM_SIZE, SAMPLED_GEOM_SIZE);
            if (sampledGeometryHandles.getNumPixelClasses() != sampledImage.getNumPixelClasses()) {
                throw new RuntimeException("DitherIndexImage.dither()-->image.numPixelClasses = " + sampledGeometryHandles.getNumPixelClasses() + ", and Geometry.getSampledImage()-->image.numPixelClasses = " + sampledImage.getNumPixelClasses());
            }
        } else {
            // Make bogus box for compartmental geometries
            int COMPARTMENT_SIZE_X = 10;
            int COMPARTMENT_SIZE_Y = 10;
            int compartmentalXY = COMPARTMENT_SIZE_X * COMPARTMENT_SIZE_Y;
            byte[] compartmentalPixels = new byte[compartmentalXY];
            for (int c = 0; c < compartmentalXY; c += 1) {
                compartmentalPixels[c] = ((byte[]) (sampledImage.getPixels()))[0];
            }
            sampledGeometryHandles = new cbit.image.VCImageUncompressed(null, compartmentalPixels, new org.vcell.util.Extent(1, 1, 1), COMPARTMENT_SIZE_X, COMPARTMENT_SIZE_Y, 1);
        }
        MemoryImageSource mis = new MemoryImageSource(sampledGeometryHandles.getNumX(), sampledGeometryHandles.getNumY(), DisplayAdapterService.getHandleColorMap(), sampledGeometryHandles.getPixels(), 0, sampledGeometryHandles.getNumX());
        java.awt.Image sampledGeometryImage = java.awt.Toolkit.getDefaultToolkit().createImage(mis);
        return new javax.swing.ImageIcon(sampledGeometryImage, "preview of Geometry");
    }
}
Also used : Extent(org.vcell.util.Extent) VCImage(cbit.image.VCImage) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 10 with MemoryImageSource

use of java.awt.image.MemoryImageSource in project Lucee by lucee.

the class ImageCombiningFilter method filter.

public ImageProducer filter(Image image1, Image image2, int x, int y, int w, int h) {
    int[] pixels1 = new int[w * h];
    int[] pixels2 = new int[w * h];
    int[] pixels3 = new int[w * h];
    PixelGrabber pg1 = new PixelGrabber(image1, x, y, w, h, pixels1, 0, w);
    PixelGrabber pg2 = new PixelGrabber(image2, x, y, w, h, pixels2, 0, w);
    try {
        pg1.grabPixels();
        pg2.grabPixels();
    } catch (InterruptedException e) {
        System.err.println("interrupted waiting for pixels!");
        return null;
    }
    if ((pg1.status() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return null;
    }
    if ((pg2.status() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return null;
    }
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            int k = j * w + i;
            pixels3[k] = filterRGB(x + i, y + j, pixels1[k], pixels2[k]);
        }
    }
    return new MemoryImageSource(w, h, pixels3, 0, w);
}
Also used : PixelGrabber(java.awt.image.PixelGrabber) MemoryImageSource(java.awt.image.MemoryImageSource)

Aggregations

MemoryImageSource (java.awt.image.MemoryImageSource)10 Dimension (java.awt.Dimension)3 Frame (java.awt.Frame)3 Menu (java.awt.Menu)3 MenuBar (java.awt.MenuBar)3 PixelGrabber (java.awt.image.PixelGrabber)2 VCImage (cbit.image.VCImage)1 FileDialog (java.awt.FileDialog)1 Image (java.awt.Image)1 MediaTracker (java.awt.MediaTracker)1 MenuItem (java.awt.MenuItem)1 MenuShortcut (java.awt.MenuShortcut)1 BufferedImage (java.awt.image.BufferedImage)1 DirectColorModel (java.awt.image.DirectColorModel)1 IndexColorModel (java.awt.image.IndexColorModel)1 Extent (org.vcell.util.Extent)1