Search in sources :

Example 51 with PixelGrabber

use of java.awt.image.PixelGrabber 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 52 with PixelGrabber

use of java.awt.image.PixelGrabber 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)

Example 53 with PixelGrabber

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

the class ImageUtils method createImage.

/**
 * Cretae a BufferedImage from an ImageProducer.
 * @param producer the ImageProducer
 * @return a new TYPE_INT_ARGB BufferedImage
 */
public static BufferedImage createImage(ImageProducer producer) {
    PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new RuntimeException("Image fetch interrupted");
    }
    if ((pg.status() & ImageObserver.ABORT) != 0)
        throw new RuntimeException("Image fetch aborted");
    if ((pg.status() & ImageObserver.ERROR) != 0)
        throw new RuntimeException("Image fetch error");
    BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
    p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[]) pg.getPixels(), 0, pg.getWidth());
    return p;
}
Also used : PixelGrabber(java.awt.image.PixelGrabber) BufferedImage(java.awt.image.BufferedImage)

Example 54 with PixelGrabber

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

the class class178 method method3415.

@ObfuscatedName("i")
@ObfuscatedSignature(signature = "(Ljm;Ljm;ZII)V", garbageValue = "1394721650")
static void method3415(IndexDataBase var0, IndexDataBase var1, boolean var2, int var3) {
    if (class90.field1345) {
        if (var3 == 4) {
            class90.loginIndex = 4;
        }
    } else {
        class90.loginIndex = var3;
        Rasterizer2D.reset();
        byte[] var4 = var0.takeRecordByNames("title.jpg", "");
        BufferedImage var6 = null;
        SpritePixels var5;
        label159: {
            try {
                var6 = ImageIO.read(new ByteArrayInputStream(var4));
                int var7 = var6.getWidth();
                int var8 = var6.getHeight();
                int[] var9 = new int[var8 * var7];
                PixelGrabber var10 = new PixelGrabber(var6, 0, 0, var7, var8, var9, 0, var7);
                var10.grabPixels();
                var5 = new SpritePixels(var9, var7, var8);
                break label159;
            } catch (IOException var13) {
                ;
            } catch (InterruptedException var14) {
                ;
            }
            var5 = new SpritePixels(0, 0);
        }
        class317.field3926 = var5;
        class61.field715 = class317.field3926.method5924();
        if ((Client.flags & 536870912) != 0) {
            class90.logoSprite = class44.getSprite(var1, "logo_deadman_mode", "");
        } else {
            class90.logoSprite = class44.getSprite(var1, "logo", "");
        }
        class90.field1339 = class44.getSprite(var1, "titlebox", "");
        class203.field2605 = class44.getSprite(var1, "titlebutton", "");
        class90.runeSprites = class199.getIndexedSprites(var1, "runes", "");
        class38.titlemuteSprite = class199.getIndexedSprites(var1, "title_mute", "");
        TextureProvider.field1691 = class44.getSprite(var1, "options_radio_buttons,0", "");
        class90.field1342 = class44.getSprite(var1, "options_radio_buttons,4", "");
        class151.field2127 = class44.getSprite(var1, "options_radio_buttons,2", "");
        class304.field3848 = class44.getSprite(var1, "options_radio_buttons,6", "");
        class90.field1363 = TextureProvider.field1691.width;
        WorldMapType1.field415 = TextureProvider.field1691.height;
        class38.field489 = new int[256];
        int var12;
        for (var12 = 0; var12 < 64; ++var12) {
            class38.field489[var12] = var12 * 262144;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class38.field489[var12 + 64] = var12 * 1024 + 16711680;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class38.field489[var12 + 128] = var12 * 4 + 16776960;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class38.field489[var12 + 192] = 16777215;
        }
        class7.field231 = new int[256];
        for (var12 = 0; var12 < 64; ++var12) {
            class7.field231[var12] = var12 * 1024;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class7.field231[var12 + 64] = var12 * 4 + 65280;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class7.field231[var12 + 128] = var12 * 262144 + 65535;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class7.field231[var12 + 192] = 16777215;
        }
        class36.field480 = new int[256];
        for (var12 = 0; var12 < 64; ++var12) {
            class36.field480[var12] = var12 * 4;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class36.field480[var12 + 64] = var12 * 262144 + 255;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class36.field480[var12 + 128] = var12 * 1024 + 16711935;
        }
        for (var12 = 0; var12 < 64; ++var12) {
            class36.field480[var12 + 192] = 16777215;
        }
        Item.field1408 = new int[256];
        BaseVarType.field30 = new int['耀'];
        class5.field34 = new int['耀'];
        class20.method169((IndexedSprite) null);
        class90.field1362 = new int['耀'];
        RunException.field2181 = new int['耀'];
        if (var2) {
            class90.username = "";
            class90.password = "";
        }
        PendingSpawn.field1145 = 0;
        MapCacheArchiveNames.field520 = "";
        class90.field1344 = true;
        class90.worldSelectShown = false;
        if (!class46.preferences.muted) {
            class158.method3185(2, class1.indexTrack1, "scape main", "", 255, false);
        } else {
            IndexStoreActionHandler.method4660(2);
        }
        class189.sendConInfo(false);
        class90.field1345 = true;
        class90.field1338 = (Sequence.canvasWidth - 765) / 2;
        class90.loginWindowX = class90.field1338 + 202;
        GameCanvas.field630 = class90.loginWindowX + 180;
        class317.field3926.method5868(class90.field1338, 0);
        class61.field715.method5868(class90.field1338 + 382, 0);
        class90.logoSprite.method5842(class90.field1338 + 382 - class90.logoSprite.width / 2, 18);
    }
}
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 55 with PixelGrabber

use of java.awt.image.PixelGrabber in project logisim-evolution by reds-heig.

the class ImageXmlFactory method CreateStream.

public void CreateStream(Image BoardPicture) {
    BufferedImage result = new BufferedImage(740, 400, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g2 = result.createGraphics();
    int width = BoardPicture.getWidth(null);
    int hight = BoardPicture.getHeight(null);
    PixelGrabber pixelGrabber = new PixelGrabber(BoardPicture, 0, 0, width, hight, false);
    try {
        pixelGrabber.grabPixels();
    } catch (Exception e) {
        /* TODO: handle exceptions */
        logger.error("PixelGrabber exception: {}", e.getMessage());
    }
    ColorModel color_model = pixelGrabber.getColorModel();
    if (pixelGrabber.getPixels() instanceof byte[]) {
        byte[] the_pixels = (byte[]) pixelGrabber.getPixels();
        int index = 0;
        for (int y = 0; y < hight; y++) {
            for (int x = 0; x < width; x++) {
                Color PixCol = new Color(color_model.getRed(the_pixels[index]), color_model.getGreen(the_pixels[index]), color_model.getBlue(the_pixels[index++]));
                g2.setColor(PixCol);
                g2.fillRect(x, y, 1, 1);
            }
        }
    } else {
        int[] the_pixels = (int[]) pixelGrabber.getPixels();
        int index = 0;
        for (int y = 0; y < hight; y++) {
            for (int x = 0; x < width; x++) {
                Color PixCol = new Color(color_model.getRed(the_pixels[index]), color_model.getGreen(the_pixels[index]), color_model.getBlue(the_pixels[index++]));
                g2.setColor(PixCol);
                g2.fillRect(x, y, 1, 1);
            }
        }
    }
    ByteArrayOutputStream blaat = new ByteArrayOutputStream();
    try {
        ImageIO.write(result, "jpg", blaat);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        logger.error("JPEG Writer exception: {}", e.getMessage());
    }
    byte[] data = blaat.toByteArray();
    CodeTable = CreateCodeTable(data);
    AsciiStream = new StringBuffer();
    AsciiStream.append(V2_Identifier);
    for (int i = 0; i < data.length; i++) {
        String code = CodeTable[data[i] + 128];
        AsciiStream.append(code);
    }
}
Also used : Color(java.awt.Color) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) Graphics2D(java.awt.Graphics2D) ColorModel(java.awt.image.ColorModel) 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