use of java.awt.image.PixelGrabber in project mars-sim by mars-sim.
the class StarRater method imageToCompressedByteArray.
/**
* Converts an image to a compressed byte array. GZIPs the image to reduce the size. Use compressedByteArrayToImage(byte[] data) to
* retrieve the original image. The image is not recognizable as image from standard tools.
*
* @param image The image to convert.
* @return The byte array.
* @throws IOException if something goes wrong.
*/
public byte[] imageToCompressedByteArray(Image image) throws IOException {
// get image size
int width = image.getWidth(null);
int height = image.getHeight(null);
// store image data as raw int values
try {
int[] imageSource = new int[width * height];
PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, imageSource, 0, width);
pg.grabPixels();
// zip data
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
GZIPOutputStream zippedStream = new GZIPOutputStream(byteStream);
ObjectOutputStream objectStream = new ObjectOutputStream(zippedStream);
objectStream.writeShort(width);
objectStream.writeShort(height);
objectStream.writeObject(imageSource);
objectStream.flush();
objectStream.close();
return byteStream.toByteArray();
} catch (Exception e) {
throw new IOException("Error storing image in object: " + e);
}
}
use of java.awt.image.PixelGrabber in project openosrs-dev by blurite.
the class class29 method method433.
@ObfuscatedName("v")
@ObfuscatedSignature(descriptor = "([BS)Lql;", garbageValue = "-13194")
public static final SpritePixels method433(byte[] var0) {
// L: 20
BufferedImage var1 = null;
try {
// L: 22
var1 = ImageIO.read(new ByteArrayInputStream(var0));
// L: 23
int var2 = var1.getWidth();
// L: 24
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);
}
use of java.awt.image.PixelGrabber in project unethicalite by unethicalite.
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());
}
use of java.awt.image.PixelGrabber in project client by DarkanRS.
the class Class103_Sub1 method method14490.
static NativeSprite method14490(byte[] bytes_0) {
if (bytes_0 == null) {
throw new RuntimeException("");
} else {
while (true) {
try {
Image image_3 = Toolkit.getDefaultToolkit().createImage(bytes_0);
MediaTracker mediatracker_4 = new MediaTracker(SubInterface.suppliedApplet);
mediatracker_4.addImage(image_3, 0);
mediatracker_4.waitForAll();
int i_5 = image_3.getWidth(SubInterface.suppliedApplet);
int i_6 = image_3.getHeight(SubInterface.suppliedApplet);
if (!mediatracker_4.isErrorAny() && i_5 >= 0 && i_6 >= 0) {
int[] ints_7 = new int[i_5 * i_6];
PixelGrabber pixelgrabber_8 = new PixelGrabber(image_3, 0, 0, i_5, i_6, ints_7, 0, i_5);
pixelgrabber_8.grabPixels();
NativeSprite nativesprite_2 = Renderers.CURRENT_RENDERER.createNativeSprite(ints_7, i_5, i_5, i_6);
return nativesprite_2;
}
throw new RuntimeException("");
} catch (InterruptedException ignored) {
}
}
}
}
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;
}
Aggregations