Search in sources :

Example 36 with PixelGrabber

use of java.awt.image.PixelGrabber in project CFT by rfo909.

the class RasterImage method init.

private void init(Image img) throws Exception {
    this.w = img.getWidth(null);
    this.h = img.getHeight(null);
    int[] pix = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
    pg.grabPixels();
    pixels = pix;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 37 with PixelGrabber

use of java.awt.image.PixelGrabber in project selenium-shutterbug by assertthat.

the class ImageProcessor method hasAlpha.

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 ignored) {
    }
    // 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 38 with PixelGrabber

use of java.awt.image.PixelGrabber in project datawarrior by thsa.

the class Text3D method plotImage.

public static void plotImage(int x, int y, int z, Image image, Graphics3D g3d, JmolRendererInterface jmolRenderer, boolean antialias, int argbBackground, int width, int height) {
    boolean isBackground = (x == Integer.MIN_VALUE);
    int width0 = image.getWidth(null);
    int height0 = image.getHeight(null);
    if (isBackground) {
        x = 0;
        z = Integer.MAX_VALUE - 1;
        width = g3d.width;
        height = g3d.height;
    }
    if (x + width <= 0 || x >= g3d.width || y + height <= 0 || y >= g3d.height)
        return;
    g3d.platform.checkOffscreenSize(width, height);
    Graphics g = g3d.platform.gOffscreen;
    g.clearRect(0, 0, width, height);
    g.drawImage(image, 0, 0, width, height, 0, 0, width0, height0, null);
    PixelGrabber pixelGrabber = new PixelGrabber(g3d.platform.imageOffscreen, 0, 0, width, height, true);
    try {
        pixelGrabber.grabPixels();
    } catch (InterruptedException e) {
        // impossible?
        return;
    }
    int[] buffer = (int[]) pixelGrabber.getPixels();
    int bgcolor = (isBackground ? 0 : argbBackground == 0 ? buffer[0] : argbBackground);
    if (jmolRenderer != null || (x < 0 || x + width > g3d.width || y < 0 || y + height > g3d.height))
        plotImageClipped(x, y, z, g3d, jmolRenderer, width, height, buffer, bgcolor);
    else
        plotImageUnClipped(x, y, z, g3d, width, height, buffer, bgcolor);
    return;
}
Also used : Graphics(java.awt.Graphics) PixelGrabber(java.awt.image.PixelGrabber)

Example 39 with PixelGrabber

use of java.awt.image.PixelGrabber in project datawarrior by thsa.

the class Text3D method rasterize.

private void rasterize(Platform3D platform, boolean antialias) {
    PixelGrabber pixelGrabber = new PixelGrabber(platform.imageOffscreen, 0, 0, mapWidth, height, true);
    try {
        pixelGrabber.grabPixels();
    } catch (InterruptedException e) {
        // impossible?
        return;
    }
    int[] pixels = (int[]) pixelGrabber.getPixels();
    int bitmapSize = (size + 31) >> 5;
    bitmap = new int[bitmapSize];
    int offset, shifter;
    for (offset = shifter = 0; offset < size; ++offset, shifter <<= 1) {
        if ((pixels[offset] & 0x00FFFFFF) != 0)
            shifter |= 1;
        if ((offset & 31) == 31)
            bitmap[offset >> 5] = shifter;
    }
    if ((offset & 31) != 0) {
        shifter <<= 31 - (offset & 31);
        bitmap[offset >> 5] = shifter;
    }
/*      // error checking
      // shifter error checking
      boolean[] bits = new boolean[size];
      for (int i = 0; i < size; ++i)
        bits[i] = (pixels[i] & 0x00FFFFFF) != 0;
      //
      for (offset = 0; offset < size; ++offset, shifter <<= 1) {
        if ((offset & 31) == 0)
          shifter = bitmap[offset >> 5];
        if (shifter < 0) {
          if (!bits[offset]) {
            Logger.debug("false positive @" + offset);
            Logger.debug("size = " + size);
          }
        } else {
          if (bits[offset]) {
            Logger.debug("false negative @" + offset);
            Logger.debug("size = " + size);
          }
        }
      }
      // error checking
    */
}
Also used : PixelGrabber(java.awt.image.PixelGrabber)

Example 40 with PixelGrabber

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

the class Image method grabPixels.

static int[] grabPixels(Object imageobj, int width, int height, int[] pixels, int startRow, int nRows) {
    java.awt.Image image = (java.awt.Image) imageobj;
    PixelGrabber pixelGrabber = (pixels == null ? new PixelGrabber(image, 0, 0, width, height, true) : new PixelGrabber(image, 0, startRow, width, nRows, pixels, 0, width));
    try {
        pixelGrabber.grabPixels();
    } catch (InterruptedException e) {
        return null;
    }
    return (int[]) pixelGrabber.getPixels();
}
Also used : PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Aggregations

PixelGrabber (java.awt.image.PixelGrabber)82 BufferedImage (java.awt.image.BufferedImage)34 ColorModel (java.awt.image.ColorModel)17 IOException (java.io.IOException)16 Image (java.awt.Image)11 Color (java.awt.Color)9 DirectColorModel (java.awt.image.DirectColorModel)6 Point2D (java.awt.geom.Point2D)5 MemoryImageSource (java.awt.image.MemoryImageSource)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 URL (java.net.URL)2