Search in sources :

Example 81 with PixelGrabber

use of java.awt.image.PixelGrabber in project mars-sim by mars-sim.

the class RandomMineralMap method getTopoRegionSet.

/**
 * Gets a set of location coordinates representing a topographical region.
 *
 * @param imageMapName the topographical region map image.
 * @return set of location coordinates.
 */
private Set<Coordinates> getTopoRegionSet(String imageMapName) {
    Set<Coordinates> result = new HashSet<Coordinates>(3000);
    // [landrus, 26.11.09]: don't use the system classloader in a webstart env.
    URL imageMapURL = getClass().getResource("/images/" + imageMapName);
    ImageIcon mapIcon = new ImageIcon(imageMapURL);
    Image mapImage = mapIcon.getImage();
    int[] mapPixels = new int[W * H];
    PixelGrabber topoGrabber = new PixelGrabber(mapImage, 0, 0, W, H, mapPixels, 0, W);
    try {
        topoGrabber.grabPixels();
    } catch (InterruptedException e) {
        logger.log(Level.SEVERE, "grabber error" + e);
        // Restore interrupted state
        Thread.currentThread().interrupt();
    }
    if ((topoGrabber.status() & ImageObserver.ABORT) != 0)
        logger.info("grabber error");
    for (int x = 0; x < H; x++) {
        for (int y = 0; y < W; y++) {
            int pixel = mapPixels[(x * W) + y];
            Color color = new Color(pixel);
            if (Color.white.equals(color)) {
                double pixel_offset = (Math.PI / 150D) / 2D;
                double phi = (((double) x / 150D) * Math.PI) + pixel_offset;
                double theta = (((double) y / 150D) * Math.PI) + Math.PI + pixel_offset;
                if (theta > (2D * Math.PI))
                    theta -= (2D * Math.PI);
                result.add(new Coordinates(phi, theta));
            }
        }
    }
    return result;
}
Also used : ImageIcon(javax.swing.ImageIcon) Coordinates(org.mars_sim.msp.core.Coordinates) Color(java.awt.Color) PixelGrabber(java.awt.image.PixelGrabber) Image(java.awt.Image) URL(java.net.URL) HashSet(java.util.HashSet)

Example 82 with PixelGrabber

use of java.awt.image.PixelGrabber in project mars-sim by mars-sim.

the class AreothermalMap method loadHotspots.

/**
 * Load areothermal hot spots from volcanic map image.
 */
private void loadHotspots() {
    hotspots = new HashSet<Coordinates>(700);
    URL imageMapURL = getClass().getResource("/images/" + VOLCANIC_IMG);
    ImageIcon mapIcon = new ImageIcon(imageMapURL);
    Image mapImage = mapIcon.getImage();
    int[] mapPixels = new int[W * H];
    PixelGrabber grabber = new PixelGrabber(mapImage, 0, 0, W, H, mapPixels, 0, W);
    try {
        grabber.grabPixels();
    } catch (InterruptedException e) {
        logger.log(Level.SEVERE, "grabber error" + e);
        // Restore interrupted state
        Thread.currentThread().interrupt();
    }
    if ((grabber.status() & ImageObserver.ABORT) != 0)
        logger.severe("grabber error");
    for (int x = 0; x < H; x++) {
        for (int y = 0; y < W; y++) {
            int pixel = mapPixels[(x * W) + y];
            Color color = new Color(pixel);
            if (Color.white.equals(color)) {
                double pixel_offset = (Math.PI / 150D) / 2D;
                double phi = (((double) x / 150D) * Math.PI) + pixel_offset;
                double theta = (((double) y / 150D) * Math.PI) + Math.PI + pixel_offset;
                if (theta > (2D * Math.PI))
                    theta -= (2D * Math.PI);
                hotspots.add(new Coordinates(phi, theta));
            }
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) Coordinates(org.mars_sim.msp.core.Coordinates) Color(java.awt.Color) PixelGrabber(java.awt.image.PixelGrabber) Image(java.awt.Image) URL(java.net.URL)

Example 83 with PixelGrabber

use of java.awt.image.PixelGrabber in project MeteoInfo by meteoinfo.

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)

Example 84 with PixelGrabber

use of java.awt.image.PixelGrabber in project runelite by open-osrs.

the class class125 method method2743.

// L: 124
@ObfuscatedName("c")
@ObfuscatedSignature(descriptor = "([BI)Lpt;", garbageValue = "-2047697021")
public static final SpritePixels method2743(byte[] var0) {
    // L: 20
    BufferedImage var1 = null;
    try {
        // L: 22
        var1 = ImageIO.read(new ByteArrayInputStream(var0));
        // L: 23
        int var2 = var1.getWidth();
        int var3 = var1.getHeight();
        // L: 25
        int[] var4 = new int[var3 * var2];
        // L: 26
        PixelGrabber var5 = new PixelGrabber(var1, 0, 0, var2, var3, var4, 0, var2);
        // L: 27
        var5.grabPixels();
        // L: 28
        return new SpritePixels(var4, var2, var3);
    } catch (IOException var7) {
    // L: 30
    } catch (InterruptedException var8) {
    // L: 31
    }
    // L: 32
    return new SpritePixels(0, 0);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PixelGrabber(java.awt.image.PixelGrabber) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) ObfuscatedSignature(net.runelite.mapping.ObfuscatedSignature) ObfuscatedName(net.runelite.mapping.ObfuscatedName)

Example 85 with PixelGrabber

use of java.awt.image.PixelGrabber in project workstation by JaneliaSciComp.

the class Utils method hasAlpha.

/**
 * This method returns true if the specified image has transparent pixels.
 * From http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html
 */
public static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().hasAlpha();
    }
    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        log.warn("failed to grab pixels for " + image, e);
    }
    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}
Also used : ColorModel(java.awt.image.ColorModel) PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Aggregations

PixelGrabber (java.awt.image.PixelGrabber)88 BufferedImage (java.awt.image.BufferedImage)37 ColorModel (java.awt.image.ColorModel)20 IOException (java.io.IOException)17 Image (java.awt.Image)13 Color (java.awt.Color)9 DirectColorModel (java.awt.image.DirectColorModel)7 MemoryImageSource (java.awt.image.MemoryImageSource)6 Point2D (java.awt.geom.Point2D)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 ObfuscatedName (net.runelite.mapping.ObfuscatedName)5 ObfuscatedSignature (net.runelite.mapping.ObfuscatedSignature)5 Graphics2D (java.awt.Graphics2D)3 MediaTracker (java.awt.MediaTracker)3 ByteProcessor (ij.process.ByteProcessor)2 AWTException (java.awt.AWTException)2 Graphics (java.awt.Graphics)2 IndexColorModel (java.awt.image.IndexColorModel)2 WritableRaster (java.awt.image.WritableRaster)2