Search in sources :

Example 71 with PixelGrabber

use of java.awt.image.PixelGrabber in project astroimagej by AstroImageJ.

the class AstroStackWindow method hasAlpha.

// This method returns true if the specified image has transparent pixels
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) {
    }
    // 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)

Example 72 with PixelGrabber

use of java.awt.image.PixelGrabber in project astroimagej by AstroImageJ.

the class ImagePlus method getPixel.

/**
 *	Returns the pixel value at (x,y) as a 4 element array. Grayscale values
 *	are retuned in the first element. RGB values are returned in the first
 *	3 elements. For indexed color images, the RGB values are returned in the
 *	first 3 three elements and the index (0-255) is returned in the last.
 */
public int[] getPixel(int x, int y) {
    pvalue[0] = pvalue[1] = pvalue[2] = pvalue[3] = 0;
    switch(imageType) {
        case GRAY8:
        case COLOR_256:
            int index;
            if (ip != null)
                index = ip.getPixel(x, y);
            else {
                byte[] pixels8;
                if (img == null)
                    return pvalue;
                PixelGrabber pg = new PixelGrabber(img, x, y, 1, 1, false);
                try {
                    pg.grabPixels();
                } catch (InterruptedException e) {
                    return pvalue;
                }
                ;
                pixels8 = (byte[]) (pg.getPixels());
                index = pixels8 != null ? pixels8[0] & 0xff : 0;
            }
            if (imageType != COLOR_256) {
                pvalue[0] = index;
                return pvalue;
            }
            pvalue[3] = index;
        // fall through to get rgb values
        case COLOR_RGB:
            if (ip != null && ip.getNChannels() == 1) {
                pvalue[0] = ip.getPixel(x, y);
                return pvalue;
            }
            int c = 0;
            if (imageType == COLOR_RGB && ip != null)
                c = ip.getPixel(x, y);
            else {
                int[] pixels32 = new int[1];
                if (img == null)
                    return pvalue;
                PixelGrabber pg = new PixelGrabber(img, x, y, 1, 1, pixels32, 0, width);
                try {
                    pg.grabPixels();
                } catch (InterruptedException e) {
                    return pvalue;
                }
                ;
                c = pixels32[0];
            }
            int r = (c & 0xff0000) >> 16;
            int g = (c & 0xff00) >> 8;
            int b = c & 0xff;
            pvalue[0] = r;
            pvalue[1] = g;
            pvalue[2] = b;
            break;
        case GRAY16:
        case GRAY32:
            if (ip != null)
                pvalue[0] = ip.getPixel(x, y);
            break;
    }
    return pvalue;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 73 with PixelGrabber

use of java.awt.image.PixelGrabber in project HO by akasolace.

the class PluginIfaUtils method getPixels.

private static int[][] getPixels(Image image) throws IOException {
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    int[] pix = new int[w * h];
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, w, h, pix, 0, w);
    try {
        if (!grabber.grabPixels())
            throw new IOException("Grabber returned false: " + grabber.status());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    int[][] pixels = new int[w][h];
    for (int x = w; x-- > 0; ) {
        for (int y = h; y-- > 0; ) {
            pixels[x][y] = pix[(y * w + x)];
        }
    }
    return pixels;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber) IOException(java.io.IOException)

Example 74 with PixelGrabber

use of java.awt.image.PixelGrabber in project platform by lsfusion.

the class SerializableImageIconHolder method writeObject.

private void writeObject(ObjectOutputStream s) throws IOException {
    s.writeObject(imagePath);
    s.writeInt(images.size());
    for (Map.Entry<ColorTheme, ImageIcon> imagesEntry : images.entrySet()) {
        ImageIcon image = imagesEntry.getValue();
        s.writeBoolean(image != null);
        if (image != null) {
            s.writeObject(imagesEntry.getKey());
            int w = image.getIconWidth();
            int h = image.getIconHeight();
            int[] pixels = image.getImage() != null ? new int[w * h] : null;
            if (image.getImage() != null) {
                try {
                    PixelGrabber pg = new PixelGrabber(image.getImage(), 0, 0, w, h, pixels, 0, w);
                    pg.grabPixels();
                    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                        throw new IOException("failed to load image contents");
                    }
                } catch (InterruptedException e) {
                    throw new IOException("image load interrupted");
                }
            }
            s.writeInt(w);
            s.writeInt(h);
            s.writeObject(pixels);
        }
    }
}
Also used : ColorTheme(lsfusion.interop.base.view.ColorTheme) PixelGrabber(java.awt.image.PixelGrabber) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 75 with PixelGrabber

use of java.awt.image.PixelGrabber in project client by DarkanRS.

the class Class194 method method3179.

void method3179(AbstractRenderer graphicalrenderer_1, Font font_2, java.awt.FontMetrics fontmetrics_3, char var_4, int i_5, boolean bool_6) {
    boolean bool_61 = bool_6;
    int i_7 = fontmetrics_3.charWidth(var_4);
    int i_8 = i_7;
    if (bool_61) {
        try {
            if (var_4 == 47) {
                bool_61 = false;
            }
            if (var_4 == 102 || var_4 == 116 || var_4 == 119 || var_4 == 118 || var_4 == 107 || var_4 == 120 || var_4 == 121 || var_4 == 65 || var_4 == 86 || var_4 == 87) {
                ++i_7;
            }
        } catch (Exception ignored) {
        }
    }
    int i_21 = fontmetrics_3.getMaxAscent();
    int i_10 = fontmetrics_3.getMaxAscent() + fontmetrics_3.getMaxDescent();
    int i_11 = fontmetrics_3.getHeight();
    Image image_12 = Class351.gameCanvas.createImage(i_7, i_10);
    Graphics graphics_13 = image_12.getGraphics();
    graphics_13.setColor(Color.black);
    graphics_13.fillRect(0, 0, i_7, i_10);
    graphics_13.setColor(Color.white);
    graphics_13.setFont(font_2);
    graphics_13.drawString(var_4 + "", 0, i_21);
    if (bool_61) {
        graphics_13.drawString(var_4 + "", 1, i_21);
    }
    int[] ints_14 = new int[i_7 * i_10];
    PixelGrabber pixelgrabber_15 = new PixelGrabber(image_12, 0, 0, i_7, i_10, ints_14, 0, i_7);
    try {
        pixelgrabber_15.grabPixels();
    } catch (Exception ignored) {
    }
    image_12.flush();
    Object obj_16 = null;
    int i_17 = 0;
    int i_18;
    label66: for (i_18 = 0; i_18 < i_10; i_18++) {
        for (int i_19 = 0; i_19 < i_7; i_19++) {
            int i_20 = ints_14[i_19 + i_18 * i_7];
            if ((i_20 & 0xffffff) != 0) {
                i_17 = i_18;
                break label66;
            }
        }
    }
    for (i_18 = 0; i_18 < ints_14.length; i_18++) {
        if ((ints_14[i_18] & 0xffffff) == 0) {
            ints_14[i_18] = 0;
        }
    }
    anInt2407 = i_21 - i_17;
    anInt2408 = i_11;
    anIntArray2403[i_5] = i_8;
    aNativeSpriteArray2405[i_5] = graphicalrenderer_1.createNativeSprite(ints_14, i_7, i_7, i_10);
}
Also used : Graphics(java.awt.Graphics) PixelGrabber(java.awt.image.PixelGrabber) Image(java.awt.Image)

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