summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/ImageConverter.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/ImageConverter.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/ImageConverter.java')
-rw-r--r--NET/worlds/scape/ImageConverter.java181
1 files changed, 181 insertions, 0 deletions
diff --git a/NET/worlds/scape/ImageConverter.java b/NET/worlds/scape/ImageConverter.java
new file mode 100644
index 0000000..091ba1f
--- /dev/null
+++ b/NET/worlds/scape/ImageConverter.java
@@ -0,0 +1,181 @@
+package NET.worlds.scape;
+
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.awt.image.ColorModel;
+import java.awt.image.DirectColorModel;
+import java.awt.image.ImageConsumer;
+import java.awt.image.IndexColorModel;
+import java.util.Hashtable;
+
+public class ImageConverter implements ImageConsumer {
+ private String urlName;
+ private String filename;
+ private int width;
+ private int height;
+ private Image image;
+ private boolean done;
+ private boolean ok;
+ private boolean debug = false;
+ private ColorModel model;
+ private int transparentColor = -1;
+ private int hDIB;
+ private int pixelPtr;
+
+ static {
+ nativeInit();
+ }
+
+ public ImageConverter(String urlName, String filename) {
+ this.urlName = urlName;
+ this.filename = filename;
+ }
+
+ public static native void nativeInit();
+
+ public synchronized int convert() {
+ this.image = Toolkit.getDefaultToolkit().getImage(this.filename);
+ this.image.getSource().startProduction(this);
+
+ while (!this.done) {
+ try {
+ this.wait();
+ } catch (InterruptedException var2) {
+ }
+ }
+
+ int textureID = 0;
+ if (this.ok) {
+ textureID = this.convertDIBToTexture();
+ }
+
+ this.cleanup();
+ return textureID;
+ }
+
+ @Override
+ public void setDimensions(int width, int height) {
+ if (this.debug) {
+ System.out.println("Set dimensions: w " + width + " h " + height);
+ }
+
+ this.width = width;
+ this.height = height;
+ }
+
+ @Override
+ public void setProperties(Hashtable props) {
+ if (this.debug) {
+ System.out.println("Set properties");
+ }
+ }
+
+ @Override
+ public void setColorModel(ColorModel model) {
+ if (this.debug) {
+ System.out.println("Set color model: " + model);
+ }
+
+ this.model = model;
+
+ assert this.width != 0 && this.height != 0;
+
+ int[] palette = (int[])null;
+ int colors = 0;
+ if (model instanceof IndexColorModel) {
+ IndexColorModel im = (IndexColorModel)model;
+ colors = im.getMapSize();
+ this.transparentColor = im.getTransparentPixel();
+ palette = new int[colors * 3];
+
+ for (int i = 0; i < colors; i++) {
+ palette[i] = im.getRGB(i);
+ }
+ } else {
+ DirectColorModel dm = (DirectColorModel)model;
+
+ assert dm.getBlueMask() == 255;
+
+ assert dm.getGreenMask() == 65280;
+
+ assert dm.getRedMask() == 16711680;
+ }
+
+ this.prepareDIB(this.width, this.height, colors, palette);
+ }
+
+ @Override
+ public void setHints(int hintflags) {
+ if (this.debug) {
+ System.out
+ .println(
+ "Set hints: "
+ + ((hintflags & 1) != 0 ? " RANDOM " : "")
+ + ((hintflags & 2) != 0 ? " TOPDOWNLEFTRIGHT " : "")
+ + ((hintflags & 4) != 0 ? " COMPLETESCANS " : "")
+ + ((hintflags & 8) != 0 ? " SINGLEPASS " : "")
+ + ((hintflags & 16) != 0 ? " SINGLEFRAME " : "")
+ );
+ }
+ }
+
+ @Override
+ public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize) {
+ if (this.debug) {
+ System.out.println("setPixels(byte): x " + x + " y " + y + " w " + w + " h " + h + " model " + model + " off " + off + " scansize " + scansize);
+ }
+
+ assert model == this.model;
+
+ this.setDIBPixelBytes(x, y, w, h, pixels, off, scansize);
+ }
+
+ @Override
+ public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize) {
+ if (this.debug) {
+ System.out.println("setPixels(int): x " + x + " y " + y + " w " + w + " h " + h + " model " + model + " off " + off + " scansize " + scansize);
+ }
+
+ assert model == this.model;
+
+ this.setDIBPixelInts(x, y, w, h, pixels, off, scansize);
+ }
+
+ @Override
+ public synchronized void imageComplete(int status) {
+ if (this.debug) {
+ String state = null;
+ switch (status) {
+ case 1:
+ state = "ERROR";
+ break;
+ case 2:
+ state = "SINGLEDONE";
+ break;
+ case 3:
+ state = "STATICDONE";
+ break;
+ case 4:
+ state = "ABORTED";
+ }
+
+ System.out.println("Image complete: " + state);
+ }
+
+ this.image.getSource().removeConsumer(this);
+ this.image.flush();
+ this.ok = status != 1 && status != 4;
+ this.done = true;
+ this.notify();
+ }
+
+ private native void prepareDIB(int var1, int var2, int var3, int[] var4);
+
+ private native void setDIBPixelBytes(int var1, int var2, int var3, int var4, byte[] var5, int var6, int var7);
+
+ private native void setDIBPixelInts(int var1, int var2, int var3, int var4, int[] var5, int var6, int var7);
+
+ private native int convertDIBToTexture();
+
+ private native void cleanup();
+}