Search in sources :

Example 76 with PixelGrabber

use of java.awt.image.PixelGrabber in project metro-jax-ws by eclipse-ee4j.

the class AttachmentHelper method handlePixels.

private static Iterator handlePixels(Image img, Rectangle rect) {
    int x = rect.x;
    int y = rect.y;
    int w = rect.width;
    int h = rect.height;
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println("interrupted waiting for pixels!");
        return null;
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return null;
    }
    ArrayList tmpList = new ArrayList();
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            tmpList.add(handleSinglePixel(x + i, y + j, pixels[j * w + i]));
        }
    }
    return tmpList.iterator();
}
Also used : ArrayList(java.util.ArrayList) PixelGrabber(java.awt.image.PixelGrabber)

Example 77 with PixelGrabber

use of java.awt.image.PixelGrabber in project metro-jax-ws by eclipse-ee4j.

the class AttachmentHelper method handlePixels.

private static Iterator handlePixels(Image img, Rectangle rect) {
    int x = rect.x;
    int y = rect.y;
    int w = rect.width;
    int h = rect.height;
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println("interrupted waiting for pixels!");
        return null;
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return null;
    }
    ArrayList tmpList = new ArrayList();
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            tmpList.add(handleSinglePixel(x + i, y + j, pixels[j * w + i]));
        }
    }
    return tmpList.iterator();
}
Also used : ArrayList(java.util.ArrayList) PixelGrabber(java.awt.image.PixelGrabber)

Example 78 with PixelGrabber

use of java.awt.image.PixelGrabber in project openosrs-dev by blurite.

the class ImageUtil method getImageSpritePixels.

/**
 * Converts the buffered image into a sprite image and returns it
 * @param image  The image to be converted
 * @param client Current client instance
 * @return       The buffered image as a sprite image
 */
public static SpritePixels getImageSpritePixels(BufferedImage image, Client client) {
    int[] pixels = new int[image.getWidth() * image.getHeight()];
    try {
        PixelGrabber g = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
        g.setColorModel(new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000));
        g.grabPixels();
        // check for == 0, not actual transparency
        for (int i = 0; i < pixels.length; i++) {
            if ((pixels[i] & 0xFF000000) == 0) {
                pixels[i] = 0;
            }
        }
    } catch (InterruptedException ex) {
        log.debug("PixelGrabber was interrupted: ", ex);
    }
    return client.createSpritePixels(pixels, image.getWidth(), image.getHeight());
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) PixelGrabber(java.awt.image.PixelGrabber)

Example 79 with PixelGrabber

use of java.awt.image.PixelGrabber in project unethicalite by unethicalite.

the class class125 method method2743.

@ObfuscatedName("c")
@ObfuscatedSignature(descriptor = "([BI)Lpt;", garbageValue = "-2047697021")
public static final SpritePixels method2743(byte[] var0) {
    BufferedImage var1 = null;
    try {
        var1 = ImageIO.read(new ByteArrayInputStream(var0));
        int var2 = var1.getWidth();
        int var3 = var1.getHeight();
        int[] var4 = new int[var3 * var2];
        PixelGrabber var5 = new PixelGrabber(var1, 0, 0, var2, var3, var4, 0, var2);
        var5.grabPixels();
        return new SpritePixels(var4, var2, var3);
    } catch (IOException var7) {
    } catch (InterruptedException var8) {
    }
    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 80 with PixelGrabber

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

the class PerformanceTest method pixelGrabber.

public static int[] pixelGrabber(Image image) {
    // image.getWidth();
    int W = 300;
    // image.getHeight();
    int H = 150;
    int[] mapPixels = new int[W * H];
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, W, H, mapPixels, 0, W);
    try {
        grabber.grabPixels();
    } catch (InterruptedException e) {
        System.out.println("grabber error");
    }
    if ((grabber.status() & ImageObserver.ABORT) != 0)
        System.out.println("grabber error");
    return mapPixels;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

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