diff options
Diffstat (limited to 'src/net/java/games')
-rw-r--r-- | src/net/java/games/jogl/util/BitmapCharRec.java (renamed from src/net/java/games/util/BitmapCharRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BitmapFontRec.java (renamed from src/net/java/games/util/BitmapFontRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BufferUtils.java (renamed from src/net/java/games/util/BufferUtils.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/CoordRec.java (renamed from src/net/java/games/util/CoordRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUT.java (renamed from src/net/java/games/util/GLUT.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmap8x13.java (renamed from src/net/java/games/util/GLUTBitmap8x13.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmap9x15.java (renamed from src/net/java/games/util/GLUTBitmap9x15.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java (renamed from src/net/java/games/util/GLUTBitmapHelvetica10.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java (renamed from src/net/java/games/util/GLUTBitmapHelvetica12.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java (renamed from src/net/java/games/util/GLUTBitmapHelvetica18.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java (renamed from src/net/java/games/util/GLUTBitmapTimesRoman10.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java (renamed from src/net/java/games/util/GLUTBitmapTimesRoman24.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java (renamed from src/net/java/games/util/GLUTStrokeMonoRoman.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTStrokeRoman.java (renamed from src/net/java/games/util/GLUTStrokeRoman.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/StrokeCharRec.java (renamed from src/net/java/games/util/StrokeCharRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/StrokeFontRec.java (renamed from src/net/java/games/util/StrokeFontRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/StrokeRec.java (renamed from src/net/java/games/util/StrokeRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/util/DDSReader.java | 413 | ||||
-rw-r--r-- | src/net/java/games/util/DurationTimer.java | 66 | ||||
-rw-r--r-- | src/net/java/games/util/DxTex.java | 375 | ||||
-rw-r--r-- | src/net/java/games/util/LEDataInputStream.java | 223 | ||||
-rw-r--r-- | src/net/java/games/util/TGAImage.java | 310 |
22 files changed, 17 insertions, 1404 deletions
diff --git a/src/net/java/games/util/BitmapCharRec.java b/src/net/java/games/jogl/util/BitmapCharRec.java index 8a46c2be0..5705cf1ec 100644 --- a/src/net/java/games/util/BitmapCharRec.java +++ b/src/net/java/games/jogl/util/BitmapCharRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/BitmapFontRec.java b/src/net/java/games/jogl/util/BitmapFontRec.java index 924be1caf..bb2a40746 100644 --- a/src/net/java/games/util/BitmapFontRec.java +++ b/src/net/java/games/jogl/util/BitmapFontRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/BufferUtils.java b/src/net/java/games/jogl/util/BufferUtils.java index c6b234ba4..aa4653693 100644 --- a/src/net/java/games/util/BufferUtils.java +++ b/src/net/java/games/jogl/util/BufferUtils.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; import java.nio.*; diff --git a/src/net/java/games/util/CoordRec.java b/src/net/java/games/jogl/util/CoordRec.java index 5dc2ce3be..a99604a4e 100644 --- a/src/net/java/games/util/CoordRec.java +++ b/src/net/java/games/jogl/util/CoordRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/GLUT.java b/src/net/java/games/jogl/util/GLUT.java index cc8ba4fdc..de010e5be 100644 --- a/src/net/java/games/util/GLUT.java +++ b/src/net/java/games/jogl/util/GLUT.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; import net.java.games.jogl.*; diff --git a/src/net/java/games/util/GLUTBitmap8x13.java b/src/net/java/games/jogl/util/GLUTBitmap8x13.java index d5fa9c9ef..ee2bf0561 100644 --- a/src/net/java/games/util/GLUTBitmap8x13.java +++ b/src/net/java/games/jogl/util/GLUTBitmap8x13.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmap8x13 { diff --git a/src/net/java/games/util/GLUTBitmap9x15.java b/src/net/java/games/jogl/util/GLUTBitmap9x15.java index cd8ce8904..e2849193b 100644 --- a/src/net/java/games/util/GLUTBitmap9x15.java +++ b/src/net/java/games/jogl/util/GLUTBitmap9x15.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmap9x15 { diff --git a/src/net/java/games/util/GLUTBitmapHelvetica10.java b/src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java index d4c7b42d6..a831ad253 100644 --- a/src/net/java/games/util/GLUTBitmapHelvetica10.java +++ b/src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapHelvetica10 { diff --git a/src/net/java/games/util/GLUTBitmapHelvetica12.java b/src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java index 4b313003b..f4a0bebeb 100644 --- a/src/net/java/games/util/GLUTBitmapHelvetica12.java +++ b/src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapHelvetica12 { diff --git a/src/net/java/games/util/GLUTBitmapHelvetica18.java b/src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java index 7b8e2d0e9..2d6ca178e 100644 --- a/src/net/java/games/util/GLUTBitmapHelvetica18.java +++ b/src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapHelvetica18 { diff --git a/src/net/java/games/util/GLUTBitmapTimesRoman10.java b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java index cff580943..2d56cb899 100644 --- a/src/net/java/games/util/GLUTBitmapTimesRoman10.java +++ b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapTimesRoman10 { diff --git a/src/net/java/games/util/GLUTBitmapTimesRoman24.java b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java index 6ca1714c4..cf89907b3 100644 --- a/src/net/java/games/util/GLUTBitmapTimesRoman24.java +++ b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapTimesRoman24 { diff --git a/src/net/java/games/util/GLUTStrokeMonoRoman.java b/src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java index 0c17d22e7..a3aec0211 100644 --- a/src/net/java/games/util/GLUTStrokeMonoRoman.java +++ b/src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTStrokeMonoRoman { diff --git a/src/net/java/games/util/GLUTStrokeRoman.java b/src/net/java/games/jogl/util/GLUTStrokeRoman.java index a8f2e576e..d5d8e9bf2 100644 --- a/src/net/java/games/util/GLUTStrokeRoman.java +++ b/src/net/java/games/jogl/util/GLUTStrokeRoman.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTStrokeRoman { diff --git a/src/net/java/games/util/StrokeCharRec.java b/src/net/java/games/jogl/util/StrokeCharRec.java index 3373c516a..742a305e3 100644 --- a/src/net/java/games/util/StrokeCharRec.java +++ b/src/net/java/games/jogl/util/StrokeCharRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/StrokeFontRec.java b/src/net/java/games/jogl/util/StrokeFontRec.java index eb516c409..82734a6dd 100644 --- a/src/net/java/games/util/StrokeFontRec.java +++ b/src/net/java/games/jogl/util/StrokeFontRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/StrokeRec.java b/src/net/java/games/jogl/util/StrokeRec.java index b0eea61dd..fa4837cb7 100644 --- a/src/net/java/games/util/StrokeRec.java +++ b/src/net/java/games/jogl/util/StrokeRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/DDSReader.java b/src/net/java/games/util/DDSReader.java deleted file mode 100644 index e3b49ec95..000000000 --- a/src/net/java/games/util/DDSReader.java +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.*; -import java.nio.*; -import java.nio.channels.*; - -/** A reader for DirectDraw Surface (.dds) files, which are used to - describe textures. These files can contain multiple mipmap levels - in one file. This reader is currently minimal and does not support - all of the possible file formats. */ - -public class DDSReader { - - /** Simple class describing images and data; does not encapsulate - image format information. User is responsible for transmitting - that information in another way. */ - - public static class ImageInfo { - private ByteBuffer data; - private int width; - private int height; - - public ImageInfo(ByteBuffer data, int width, int height) { - this.data = data; this.width = width; this.height = height; - } - public int getWidth() { return width; } - public int getHeight() { return height; } - public ByteBuffer getData() { return data; } - } - - private FileInputStream fis; - private FileChannel chan; - private ByteBuffer buf; - private Header header; - - // FourCC codes (compression formats) - public static final int DXT1 = 0x31545844; - public static final int DXT2 = 0x32545844; - public static final int DXT3 = 0x33545844; - public static final int DXT4 = 0x34545844; - public static final int DXT5 = 0x35545844; - - // - // Selected bits in header flags - // - - public static final int DDSD_CAPS = 0x00000001; // Capacities are valid - public static final int DDSD_HEIGHT = 0x00000002; // Height is valid - public static final int DDSD_WIDTH = 0x00000004; // Width is valid - public static final int DDSD_PITCH = 0x00000008; // Pitch is valid - public static final int DDSD_BACKBUFFERCOUNT = 0x00000020; // Back buffer count is valid - public static final int DDSD_ZBUFFERBITDEPTH = 0x00000040; // Z-buffer bit depth is valid (shouldn't be used in DDSURFACEDESC2) - public static final int DDSD_ALPHABITDEPTH = 0x00000080; // Alpha bit depth is valid - public static final int DDSD_LPSURFACE = 0x00000800; // lpSurface is valid - public static final int DDSD_PIXELFORMAT = 0x00001000; // ddpfPixelFormat is valid - public static final int DDSD_MIPMAPCOUNT = 0x00020000; // Mip map count is valid - public static final int DDSD_LINEARSIZE = 0x00080000; // dwLinearSize is valid - public static final int DDSD_DEPTH = 0x00800000; // dwDepth is valid - - public static final int DDPF_ALPHAPIXELS = 0x00000001; // Alpha channel is present - public static final int DDPF_ALPHA = 0x00000002; // Only contains alpha information - public static final int DDPF_RGB = 0x00000040; // RGB data is present - - // Selected bits in DDS capabilities flags - public static final int DDSCAPS_TEXTURE = 0x00001000; // Can be used as a texture - public static final int DDSCAPS_MIPMAP = 0x00400000; // Is one level of a mip-map - - // Known pixel formats - public static final int D3DFMT_UNKNOWN = 0; - public static final int D3DFMT_R8G8B8 = 20; - public static final int D3DFMT_A8R8G8B8 = 21; - public static final int D3DFMT_X8R8G8B8 = 22; - - public void loadFile(String filename) throws IOException { - File file = new File(filename); - fis = new FileInputStream(filename); - chan = fis.getChannel(); - buf = chan.map(FileChannel.MapMode.READ_ONLY, - 0, (int) file.length()); - buf.order(ByteOrder.LITTLE_ENDIAN); - header = new Header(); - header.read(buf); - } - - public void close() { - try { - chan.close(); - fis.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** Test for presence/absence of surface description flags (DDSD_*) */ - public boolean isSurfaceDescFlagSet(int flag) { - return ((header.flags & flag) != 0); - } - - /** Test for presence/absence of pixel format flags (DDPF_*) */ - public boolean isPixelFormatFlagSet(int flag) { - return ((header.pfFlags & flag) != 0); - } - - /** Gets the pixel format of this texture (D3DFMT_*) based on some - heuristics. Returns D3DFMT_UNKNOWN if could not recognize the - pixel format. */ - public int getPixelFormat() { - if (isPixelFormatFlagSet(DDPF_RGB)) { - if (isPixelFormatFlagSet(DDPF_ALPHAPIXELS)) { - if (getDepth() == 32 && - header.pfRBitMask == 0x00FF0000 && - header.pfGBitMask == 0x0000FF00 && - header.pfBBitMask == 0x000000FF && - header.pfABitMask == 0xFF000000) { - return D3DFMT_A8R8G8B8; - } - } else { - if (getDepth() == 24 && - header.pfRBitMask == 0x00FF0000 && - header.pfGBitMask == 0x0000FF00 && - header.pfBBitMask == 0x000000FF) { - return D3DFMT_R8G8B8; - } else if (getDepth() == 32 && - header.pfRBitMask == 0x00FF0000 && - header.pfGBitMask == 0x0000FF00 && - header.pfBBitMask == 0x000000FF) { - return D3DFMT_X8R8G8B8; - } - } - } - - return D3DFMT_UNKNOWN; - } - - /** Indicates whether this texture is compressed. */ - public boolean isCompressed() { - return (getCompressionFormat() != 0); - } - - /** If this surface is compressed, returns the kind of compression - used (DXT1..DXT5). */ - public int getCompressionFormat() { - return header.pfFourCC; - } - - /** Width of the texture (or the top-most mipmap if mipmaps are - present) */ - public int getWidth() { - return header.width; - } - - /** Height of the texture (or the top-most mipmap if mipmaps are - present) */ - public int getHeight() { - return header.height; - } - - /** Total number of bits per pixel. Only valid if DDPF_RGB is - present. For A8R8G8B8, would be 32. */ - public int getDepth() { - return header.pfRGBBitCount; - } - - /** Number of mip maps in the texture */ - public int getNumMipMaps() { - if (!isSurfaceDescFlagSet(DDSD_MIPMAPCOUNT)) { - return 0; - } - return header.mipMapCountOrAux; - } - - /** Gets the <i>i</i>th mipmap data (0..getNumMipMaps() - 1) */ - public ImageInfo getMipMap(int map) { - if (isCompressed()) { - throw new RuntimeException("Sorry, compressed textures not supported yet"); - } - // Figure out how far to seek - int seek = 4 + header.size; - for (int i = 0; i < map; i++) { - seek += mipMapSizeInBytes(i); - } - buf.limit(seek + mipMapSizeInBytes(map)); - buf.position(seek); - ByteBuffer next = buf.slice(); - buf.position(0); - buf.limit(buf.capacity()); - return new ImageInfo(next, mipMapWidth(map), mipMapHeight(map)); - } - - /** Returns an array of ImageInfos corresponding to all mipmap - levels of this DDS file. */ - public ImageInfo[] getAllMipMaps() { - int numLevels = getNumMipMaps(); - if (numLevels == 0) { - numLevels = 1; - } - ImageInfo[] result = new ImageInfo[numLevels]; - for (int i = 0; i < numLevels; i++) { - result[i] = getMipMap(i); - } - return result; - } - - public void debugPrint() { - PrintStream tty = System.err; - tty.println("Compressed texture: " + isCompressed()); - if (isCompressed()) { - int fmt = getCompressionFormat(); - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < 4; i++) { - char c = (char) (fmt & 0xFF); - buf.append(c); - fmt = fmt >> 8; - } - tty.println("Compression format: 0x" + Integer.toHexString(getCompressionFormat()) + " (" + buf + ")"); - } - tty.println("SurfaceDesc flags:"); - boolean recognizedAny = false; - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_CAPS, "DDSD_CAPS"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_HEIGHT, "DDSD_HEIGHT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_WIDTH, "DDSD_WIDTH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_PITCH, "DDSD_PITCH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_BACKBUFFERCOUNT, "DDSD_BACKBUFFERCOUNT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_ZBUFFERBITDEPTH, "DDSD_ZBUFFERBITDEPTH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_ALPHABITDEPTH, "DDSD_ALPHABITDEPTH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_LPSURFACE, "DDSD_LPSURFACE"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_PIXELFORMAT, "DDSD_PIXELFORMAT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_MIPMAPCOUNT, "DDSD_MIPMAPCOUNT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_LINEARSIZE, "DDSD_LINEARSIZE"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_DEPTH, "DDSD_DEPTH"); - if (!recognizedAny) { - tty.println("(none)"); - } - tty.println("Raw SurfaceDesc flags: 0x" + Integer.toHexString(header.flags)); - tty.println("Pixel format flags:"); - recognizedAny = false; - recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_RGB, "DDPF_RGB"); - recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ALPHA, "DDPF_ALPHA"); - recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ALPHAPIXELS, "DDPF_ALPHAPIXELS"); - if (!recognizedAny) { - tty.println("(none)"); - } - tty.println("Raw pixel format flags: 0x" + Integer.toHexString(header.pfFlags)); - tty.println("Depth: " + getDepth()); - tty.println("Number of mip maps: " + getNumMipMaps()); - int fmt = getPixelFormat(); - tty.print("Pixel format: "); - switch (fmt) { - case D3DFMT_R8G8B8: tty.println("D3DFMT_R8G8B8"); break; - case D3DFMT_A8R8G8B8: tty.println("D3DFMT_A8R8G8B8"); break; - case D3DFMT_X8R8G8B8: tty.println("D3DFMT_X8R8G8B8"); break; - case D3DFMT_UNKNOWN: tty.println("D3DFMT_UNKNOWN"); break; - default: tty.println("(unknown pixel format " + fmt + ")"); break; - } - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private static final int MAGIC = 0x20534444; - - static class Header { - int size; // size of the DDSURFACEDESC structure - int flags; // determines what fields are valid - int height; // height of surface to be created - int width; // width of input surface - int pitchOrLinearSize; - int backBufferCountOrDepth; - int mipMapCountOrAux; // number of mip-map levels requested (in this context) - int alphaBitDepth; // depth of alpha buffer requested - int reserved1; // reserved - int surface; // pointer to the associated surface memory - // NOTE: following two entries are from DDCOLORKEY data structure - // Are overlaid with color for empty cubemap faces (unused in this reader) - int colorSpaceLowValue; - int colorSpaceHighValue; - int destBltColorSpaceLowValue; - int destBltColorSpaceHighValue; - int srcOverlayColorSpaceLowValue; - int srcOverlayColorSpaceHighValue; - int srcBltColorSpaceLowValue; - int srcBltColorSpaceHighValue; - // NOTE: following entries are from DDPIXELFORMAT data structure - // Are overlaid with flexible vertex format description of vertex - // buffers (unused in this reader) - int pfSize; // size of DDPIXELFORMAT structure - int pfFlags; // pixel format flags - int pfFourCC; // (FOURCC code) - // Following five entries have multiple interpretations, not just - // RGBA (but that's all we support right now) - int pfRGBBitCount; // how many bits per pixel - int pfRBitMask; // mask for red bits - int pfGBitMask; // mask for green bits - int pfBBitMask; // mask for blue bits - int pfABitMask; // mask for alpha channel - int ddsCaps1; // Texture and mip-map flags - int ddsCaps2; // Advanced capabilities, not yet used - int ddsCapsReserved1; - int ddsCapsReserved2; - int textureStage; // stage in multitexture cascade - - void read(ByteBuffer buf) throws IOException { - int magic = buf.getInt(); - if (magic != MAGIC) { - throw new IOException("Incorrect magic number 0x" + - Integer.toHexString(magic) + - " (expected " + MAGIC + ")"); - } - - size = buf.getInt(); - flags = buf.getInt(); - height = buf.getInt(); - width = buf.getInt(); - pitchOrLinearSize = buf.getInt(); - backBufferCountOrDepth = buf.getInt(); - mipMapCountOrAux = buf.getInt(); - alphaBitDepth = buf.getInt(); - reserved1 = buf.getInt(); - surface = buf.getInt(); - colorSpaceLowValue = buf.getInt(); - colorSpaceHighValue = buf.getInt(); - destBltColorSpaceLowValue = buf.getInt(); - destBltColorSpaceHighValue = buf.getInt(); - srcOverlayColorSpaceLowValue = buf.getInt(); - srcOverlayColorSpaceHighValue = buf.getInt(); - srcBltColorSpaceLowValue = buf.getInt(); - srcBltColorSpaceHighValue = buf.getInt(); - pfSize = buf.getInt(); - pfFlags = buf.getInt(); - pfFourCC = buf.getInt(); - pfRGBBitCount = buf.getInt(); - pfRBitMask = buf.getInt(); - pfGBitMask = buf.getInt(); - pfBBitMask = buf.getInt(); - pfABitMask = buf.getInt(); - ddsCaps1 = buf.getInt(); - ddsCaps2 = buf.getInt(); - ddsCapsReserved1 = buf.getInt(); - ddsCapsReserved2 = buf.getInt(); - textureStage = buf.getInt(); - } - } - - private int mipMapWidth(int map) { - int width = getWidth(); - for (int i = 0; i < map; i++) { - width >>= 1; - } - return width; - } - - private int mipMapHeight(int map) { - int height = getHeight(); - for (int i = 0; i < map; i++) { - height >>= 1; - } - return height; - } - - private int mipMapSizeInBytes(int map) { - int width = mipMapWidth(map); - int height = mipMapHeight(map); - return width * height * (getDepth() / 8); - } - - private boolean printIfRecognized(PrintStream tty, int flags, int flag, String what) { - if ((flags & flag) != 0) { - tty.println(what); - return true; - } - return false; - } -} diff --git a/src/net/java/games/util/DurationTimer.java b/src/net/java/games/util/DurationTimer.java deleted file mode 100644 index 8c7db686c..000000000 --- a/src/net/java/games/util/DurationTimer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -public class DurationTimer { - private long startTime; - private long accumulatedTime; - - public void reset() { - accumulatedTime = 0; - } - - public void start() { - startTime = System.currentTimeMillis(); - } - - public void stop() { - long curTime = System.currentTimeMillis(); - accumulatedTime += (curTime - startTime); - } - - public long getDuration() { - return accumulatedTime; - } - - public float getDurationAsSeconds() { - return (float) accumulatedTime / 1000.0f; - } -} diff --git a/src/net/java/games/util/DxTex.java b/src/net/java/games/util/DxTex.java deleted file mode 100644 index fc7410314..000000000 --- a/src/net/java/games/util/DxTex.java +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.*; -import java.nio.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import javax.swing.filechooser.*; - -/** Simplified clone of DxTex tool from the DirectX SDK, written in - Java using the DDSReader; tests fetching of texture data */ - -public class DxTex { - private InternalFrameListener frameListener; - private File defaultDirectory; - private JDesktopPane desktop; - private static String endl = System.getProperty("line.separator"); - private JMenu mipMapMenu; - - public static void main(String[] args) { - new DxTex().run(args); - } - - private void run(String[] args) { - defaultDirectory = new File(System.getProperty("user.dir")); - JFrame frame = new JFrame("DirectX Texture Tool"); - frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - JMenuBar menuBar = new JMenuBar(); - JMenu menu = createMenu("File", 'F', 0); - JMenuItem item = - createMenuItem("Open...", - new ActionListener() { - public void actionPerformed(ActionEvent e) { - openFile(); - } - }, - KeyEvent.VK_O, InputEvent.CTRL_MASK, - 'O', 0); - menu.add(item); - item = - createMenuItem("Exit", - new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - }, - KeyEvent.VK_Q, InputEvent.CTRL_MASK, - 'x', 1); - menu.add(item); - menuBar.add(menu); - - menu = createMenu("MipMap", 'M', 0); - menu.setEnabled(false); - mipMapMenu = menu; - menuBar.add(menu); - - frame.setJMenuBar(menuBar); - - desktop = new JDesktopPane(); - frame.getContentPane().add(desktop); - frame.setSize(640, 480); - frame.show(); - - frameListener = new InternalFrameAdapter() { - public void internalFrameActivated(InternalFrameEvent e) { - JInternalFrame ifr = e.getInternalFrame(); - if (ifr instanceof ImageFrame) { - // Recompute entries in mip map menu - final ImageFrame frame = (ImageFrame) ifr; - if (frame.getNumMipMaps() > 0) { - mipMapMenu.removeAll(); - // Add entries - for (int i = 0; i < frame.getNumMipMaps(); i++) { - final int map = i; - JMenuItem item; - String title = "Level " + (i + 1); - ActionListener listener = new ActionListener() { - public void actionPerformed(ActionEvent e) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - frame.setMipMapLevel(map); - } - }); - } - }; - if (i < 9) { - char c = (char) ('0' + i + 1); - item = createMenuItem(title, listener, c, 6); - } else { - item = createMenuItem(title, listener); - } - mipMapMenu.add(item); - } - mipMapMenu.setEnabled(true); - } else { - mipMapMenu.setEnabled(false); - } - } else { - mipMapMenu.setEnabled(false); - } - } - - public void internalFrameClosing(InternalFrameEvent e) { - desktop.remove(e.getInternalFrame()); - desktop.invalidate(); - desktop.validate(); - desktop.repaint(); - // THIS SHOULD NOT BE NECESSARY - desktop.requestFocus(); - } - - public void internalFrameClosed(InternalFrameEvent e) { - JInternalFrame ifr = e.getInternalFrame(); - if (ifr instanceof ImageFrame) { - ((ImageFrame) ifr).close(); - } - } - }; - - for (int i = 0; i < args.length; i++) { - final File file = new File(args[i]); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - openFile(file); - } - }); - } - } - - //---------------------------------------------------------------------- - // Actions - // - - private void openFile() { - JFileChooser chooser = new JFileChooser(defaultDirectory); - chooser.setMultiSelectionEnabled(false); - chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { - public boolean accept(File f) { - return (f.isDirectory() || - f.getName().endsWith(".dds")); - } - - public String getDescription() { - return "Texture files (*.dds)"; - } - }); - - int res = chooser.showOpenDialog(null); - if (res == JFileChooser.APPROVE_OPTION) { - final File file = chooser.getSelectedFile(); - defaultDirectory = file.getParentFile(); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - openFile(file); - } - }); - } - } - - private void openFile(File file) { - try { - DDSReader reader = new DDSReader(); - reader.loadFile(file.getAbsolutePath()); - showImage(file.getName(), reader, 0); - } catch (IOException e) { - showMessageDialog("Error while opening file:" + endl + - exceptionToString(e), - "Error opening file", - JOptionPane.WARNING_MESSAGE); - } - } - - //---------------------------------------------------------------------- - // Image display - // - - private void showImage(String filename, DDSReader reader, int mipMapLevel) { - try { - ImageFrame fr = new ImageFrame(filename, reader, mipMapLevel); - desktop.add(fr); - fr.show(); - } catch (Exception e) { - showMessageDialog("Error while loading file:" + endl + - exceptionToString(e), - "Error loading file", - JOptionPane.WARNING_MESSAGE); - } - } - - class ImageFrame extends JInternalFrame { - private String filename; - private DDSReader reader; - private int mipMapLevel; - private int curWidth; - private int curHeight; - private JLabel label; - - ImageFrame(String filename, DDSReader reader, int mipMapLevel) { - super(); - this.filename = filename; - this.reader = reader; - - addInternalFrameListener(frameListener); - label = new JLabel(); - JScrollPane scroller = new JScrollPane(label); - getContentPane().add(scroller); - setSize(400, 400); - setResizable(true); - setIconifiable(true); - setClosable(true); - setMipMapLevel(mipMapLevel); - } - - int getNumMipMaps() { - return reader.getNumMipMaps(); - } - - void setMipMapLevel(int level) { - mipMapLevel = level; - computeImage(); - resetTitle(); - } - - void close() { - System.err.println("Closing files"); - reader.close(); - } - - private void computeImage() { - // Get image data - reader.getNumMipMaps(); - DDSReader.ImageInfo info = reader.getMipMap(mipMapLevel); - int width = info.getWidth(); - int height = info.getHeight(); - curWidth = width; - curHeight = height; - ByteBuffer data = info.getData(); - - // Build ImageIcon out of image data - BufferedImage img = new BufferedImage(width, height, - BufferedImage.TYPE_3BYTE_BGR); - WritableRaster dst = img.getRaster(); - - int skipSize; - if (reader.getPixelFormat() == DDSReader.D3DFMT_A8R8G8B8) { - skipSize = 4; - } else if (reader.getPixelFormat() == DDSReader.D3DFMT_R8G8B8) { - skipSize = 3; - } else { - reader.close(); - throw new RuntimeException("Unsupported pixel format " + reader.getPixelFormat()); - } - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - // NOTE: highly suspicious that A comes fourth in - // A8R8G8B8...not really ARGB, but RGBA (like OpenGL) - dst.setSample(x, y, 0, data.get(skipSize * (width * y + x) + 2) & 0xFF); - dst.setSample(x, y, 1, data.get(skipSize * (width * y + x) + 1) & 0xFF); - dst.setSample(x, y, 2, data.get(skipSize * (width * y + x) + 0) & 0xFF); - } - } - - label.setIcon(new ImageIcon(img)); - } - - private void resetTitle() { - setTitle(filename + " (" + curWidth + "x" + curHeight + - ", mipmap " + (1 + mipMapLevel) + " of " + - reader.getNumMipMaps() + ")"); - } - } - - - //---------------------------------------------------------------------- - // Menu and menu item creation - // - - private static JMenu createMenu(String name, char mnemonic, int mnemonicPos) { - JMenu menu = new JMenu(name); - menu.setMnemonic(mnemonic); - menu.setDisplayedMnemonicIndex(mnemonicPos); - return menu; - } - - private static JMenuItem createMenuItem(String name, ActionListener l) { - JMenuItem item = new JMenuItem(name); - item.addActionListener(l); - return item; - } - - private static JMenuItem createMenuItemInternal(String name, ActionListener l, int accelerator, int modifiers) { - JMenuItem item = createMenuItem(name, l); - item.setAccelerator(KeyStroke.getKeyStroke(accelerator, modifiers)); - return item; - } - - private static JMenuItem createMenuItem(String name, ActionListener l, int accelerator) { - return createMenuItemInternal(name, l, accelerator, 0); - } - - private static JMenuItem createMenuItem(String name, ActionListener l, char mnemonic, int mnemonicPos) { - JMenuItem item = createMenuItem(name, l); - item.setMnemonic(mnemonic); - item.setDisplayedMnemonicIndex(mnemonicPos); - return item; - } - - private static JMenuItem createMenuItem(String name, - ActionListener l, - int accelerator, - int acceleratorMods, - char mnemonic, - int mnemonicPos) { - JMenuItem item = createMenuItemInternal(name, l, accelerator, acceleratorMods); - item.setMnemonic(mnemonic); - item.setDisplayedMnemonicIndex(mnemonicPos); - return item; - } - - private void showMessageDialog(final String message, final String title, final int jOptionPaneKind) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - JOptionPane.showInternalMessageDialog(desktop, message, title, jOptionPaneKind); - } - }); - } - - private static String exceptionToString(Exception e) { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintStream s = new PrintStream(bos); - e.printStackTrace(s); - return bos.toString(); - } -} diff --git a/src/net/java/games/util/LEDataInputStream.java b/src/net/java/games/util/LEDataInputStream.java deleted file mode 100644 index f8fc90946..000000000 --- a/src/net/java/games/util/LEDataInputStream.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.FilterInputStream; -import java.io.InputStream; -import java.io.FileInputStream; -import java.io.EOFException; -import java.io.IOException; - -/** - * Little Endian Data Input Stream. - * - * This class implements an input stream filter to allow reading - * of java native datatypes from an input stream which has those - * native datatypes stored in a little endian byte order.<p> - * - * This is the sister class of the DataInputStream which allows - * for reading of java native datatypes from an input stream with - * the datatypes stored in big endian byte order.<p> - * - * This class implements the minimum required and calls DataInputStream - * for some of the required methods for DataInput.<p> - * - * Not all methods are implemented due to lack of immediatte requirement - * for that functionality. It is not clear if it is ever going to be - * functionally required to be able to read UTF data in a LittleEndianManner<p> - * - * @author Robin Luiten - * @version 1.1 15/Dec/1997 - */ -public class LEDataInputStream extends FilterInputStream implements DataInput -{ - /** - * To reuse some of the non endian dependent methods from - * DataInputStreams methods. - */ - DataInputStream dataIn; - - public LEDataInputStream(InputStream in) - { - super(in); - dataIn = new DataInputStream(in); - } - - public void close() throws IOException - { - dataIn.close(); // better close as we create it. - // this will close underlying as well. - } - - public synchronized final int read(byte b[]) throws IOException - { - return dataIn.read(b, 0, b.length); - } - - public synchronized final int read(byte b[], int off, int len) throws IOException - { - int rl = dataIn.read(b, off, len); - return rl; - } - - public final void readFully(byte b[]) throws IOException - { - dataIn.readFully(b, 0, b.length); - } - - public final void readFully(byte b[], int off, int len) throws IOException - { - dataIn.readFully(b, off, len); - } - - public final int skipBytes(int n) throws IOException - { - return dataIn.skipBytes(n); - } - - public final boolean readBoolean() throws IOException - { - int ch = dataIn.read(); - if (ch < 0) - throw new EOFException(); - return (ch != 0); - } - - public final byte readByte() throws IOException - { - int ch = dataIn.read(); - if (ch < 0) - throw new EOFException(); - return (byte)(ch); - } - - public final int readUnsignedByte() throws IOException - { - int ch = dataIn.read(); - if (ch < 0) - throw new EOFException(); - return ch; - } - - public final short readShort() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - if ((ch1 | ch2) < 0) - throw new EOFException(); - return (short)((ch1 << 0) + (ch2 << 8)); - } - - public final int readUnsignedShort() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - if ((ch1 | ch2) < 0) - throw new EOFException(); - return (ch1 << 0) + (ch2 << 8); - } - - public final char readChar() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - if ((ch1 | ch2) < 0) - throw new EOFException(); - return (char)((ch1 << 0) + (ch2 << 8)); - } - - public final int readInt() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - int ch3 = dataIn.read(); - int ch4 = dataIn.read(); - if ((ch1 | ch2 | ch3 | ch4) < 0) - throw new EOFException(); - return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24)); - } - - public final long readLong() throws IOException - { - int i1 = readInt(); - int i2 = readInt(); - return ((long)(i1) & 0xFFFFFFFFL) + (i2 << 32); - } - - public final float readFloat() throws IOException - { - return Float.intBitsToFloat(readInt()); - } - - public final double readDouble() throws IOException - { - return Double.longBitsToDouble(readLong()); - } - - /** - * dont call this it is not implemented. - * @return empty new string - **/ - public final String readLine() throws IOException - { - return new String(); - } - - /** - * dont call this it is not implemented - * @return empty new string - **/ - public final String readUTF() throws IOException - { - return new String(); - } - - /** - * dont call this it is not implemented - * @return empty new string - **/ - public final static String readUTF(DataInput in) throws IOException - { - return new String(); - } -} - diff --git a/src/net/java/games/util/TGAImage.java b/src/net/java/games/util/TGAImage.java deleted file mode 100644 index 8963109d0..000000000 --- a/src/net/java/games/util/TGAImage.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.*; -import net.java.games.jogl.*; - -/** - * Targa image reader adapted from sources of the <a href = - * "http://java.sun.com/products/jimi/">Jimi</a> image I/O class library. - * - * <P> - * - * Image decoder for image data stored in TGA file format. - * Currently only the original TGA file format is supported. This is - * because the new TGA format has data at the end of the file, getting - * to the end of a file in an InputStream orient environment presents - * several difficulties which are avoided at the moment. - * - * <P> - * - * This is a simple decoder and is only setup to load a single image - * from the input stream - * - * <P> - * - * @author Robin Luiten - * @author Kenneth Russell - * @version $Revision$ - */ - -public class TGAImage { - private Header header; - private int format; - private byte[] data; - - private TGAImage(Header header) { - this.header = header; - } - - /** - * This class reads in all of the TGA image header in addition it also - * reads in the imageID field as it is convenient to handle that here. - * - * @author Robin Luiten - * @version 1.1 - */ - public static class Header { - /** Set of possible file format TGA types */ - public final static int TYPE_NEW = 0; - public final static int TYPE_OLD = 1; - public final static int TYPE_UNK = 2; // cant rewind stream so unknown for now. - - /** Set of possible image types in TGA file */ - public final static int NO_IMAGE = 0; // no image data - public final static int UCOLORMAPPED = 1; // uncompressed color mapped image - public final static int UTRUECOLOR = 2; // uncompressed true color image - public final static int UBLACKWHITE = 3; // uncompressed black and white image - public final static int COLORMAPPED = 9; // compressed color mapped image - public final static int TRUECOLOR = 10; // compressed true color image - public final static int BLACKWHITE = 11; // compressed black and white image - - /** Field image descriptor bitfield values definitions */ - public final static int ID_ATTRIBPERPIXEL = 0xF; - public final static int ID_LEFTTORIGHT = 0x10; - public final static int ID_TOPTOBOTTOM = 0x20; - public final static int ID_INTERLEAVE = 0xC0; - - /** Field image descriptor / interleave values */ - public final static int I_NOTINTERLEAVED = 0; - public final static int I_TWOWAY = 1; - public final static int I_FOURWAY = 2; - - /** Type of this TGA file format */ - private int tgaType; - - /** initial TGA image data fields */ - private int idLength; // byte value - private int colorMapType; // byte value - private int imageType; // byte value - - /** TGA image colour map fields */ - private int firstEntryIndex; - private int colorMapLength; - private byte colorMapEntrySize; - - /** TGA image specification fields */ - private int xOrigin; - private int yOrigin; - private int width; - private int height; - private byte pixelDepth; - private byte imageDescriptor; - - /** bitfields in imageDescriptor */ - private byte attribPerPixel; // how many attribute bits per pixel - private boolean leftToRight; // order of data on scan line - private boolean topToBottom; // order scan lines stored - private byte interleave; // how rows are stored in image data - - private byte[] imageIDbuf; - private String imageID; - - public Header(LEDataInputStream in) throws IOException { - int ret; - - tgaType = TYPE_OLD; // dont try and get footer. - - // initial header fields - idLength = in.readUnsignedByte(); - colorMapType = in.readUnsignedByte(); - imageType = in.readUnsignedByte(); - - // color map header fields - firstEntryIndex = in.readUnsignedShort(); - colorMapLength = in.readUnsignedShort(); - colorMapEntrySize = in.readByte(); - - // TGA image specification fields - xOrigin = in.readUnsignedShort(); - yOrigin = in.readUnsignedShort(); - width = in.readUnsignedShort(); - height = in.readUnsignedShort(); - pixelDepth = in.readByte(); - imageDescriptor = in.readByte(); - - attribPerPixel = (byte)(imageDescriptor & ID_ATTRIBPERPIXEL); - leftToRight = (imageDescriptor & ID_LEFTTORIGHT) != 0; // not used ? - topToBottom = (imageDescriptor & ID_TOPTOBOTTOM) != 0; - interleave = (byte)((imageDescriptor & ID_INTERLEAVE) >> 6); - - if (idLength > 0) { - imageIDbuf = new byte[idLength]; - in.read(imageIDbuf, 0, idLength); - imageID = new String(imageIDbuf, "US-ASCII"); - } - } - - public int tgaType() { return tgaType; } - - /** initial TGA image data fields */ - public int idLength() { return idLength; } - public int colorMapType() { return colorMapType; } - public int imageType() { return imageType; } - - /** TGA image colour map fields */ - public int firstEntryIndex() { return firstEntryIndex; } - public int colorMapLength() { return colorMapLength; } - public byte colorMapEntrySize() { return colorMapEntrySize; } - - /** TGA image specification fields */ - public int xOrigin() { return xOrigin; } - public int yOrigin() { return yOrigin; } - public int width() { return width; } - public int height() { return height; } - public byte pixelDepth() { return pixelDepth; } - public byte imageDescriptor() { return imageDescriptor; } - - /** bitfields in imageDescriptor */ - public byte attribPerPixel() { return attribPerPixel; } - public boolean leftToRight() { return leftToRight; } - public boolean topToBottom() { return topToBottom; } - public byte interleave() { return interleave; } - - public byte[] imageIDbuf() { return imageIDbuf; } - public String imageID() { return imageID; } - - public String toString() { - return "TGA Header " + - " id length: " + idLength + - " color map type: "+ colorMapType + - " image type: "+ imageType + - " first entry index: " + firstEntryIndex + - " color map length: " + colorMapLength + - " color map entry size: " + colorMapEntrySize + - " x Origin: " + xOrigin + - " y Origin: " + yOrigin + - " width: "+ width + - " height: "+ height + - " pixel depth: "+ pixelDepth + - " image descriptor: "+ imageDescriptor + - (imageIDbuf == null ? "" : (" ID String: " + imageID)); - } - } - - - /** - * Identifies the image type of the tga image data and loads - * it into the JimiImage structure. This was taken from the - * prototype and modified for the new Jimi structure - */ - private void decodeImage(LEDataInputStream dIn) throws IOException { - switch (header.imageType()) { - case Header.UCOLORMAPPED: - throw new IOException("TGADecoder Uncompressed Colormapped images not supported"); - - case Header.UTRUECOLOR: // pixelDepth 15, 16, 24 and 32 - switch (header.pixelDepth) { - case 16: - throw new IOException("TGADecoder Compressed 16-bit True Color images not supported"); - - case 24: - case 32: - decodeRGBImageU24_32(dIn); - break; - } - break; - - case Header.UBLACKWHITE: - throw new IOException("TGADecoder Uncompressed Grayscale images not supported"); - - case Header.COLORMAPPED: - throw new IOException("TGADecoder Compressed Colormapped images not supported"); - - case Header.TRUECOLOR: - throw new IOException("TGADecoder Compressed True Color images not supported"); - - case Header.BLACKWHITE: - throw new IOException("TGADecoder Compressed Grayscale images not supported"); - } - } - - /** - * This assumes that the body is for a 24 bit or 32 bit for a - * RGB or ARGB image respectively. - */ - private void decodeRGBImageU24_32(LEDataInputStream dIn) throws IOException { - int i; // row index - int j; // column index - int y; // output row index - int raw; // index through the raw input buffer - int rawWidth = header.width() * (header.pixelDepth() / 8); - byte[] rawBuf = new byte[rawWidth]; - data = new byte[rawWidth * header.height()]; - - if (header.pixelDepth() == 24) { - format = GL.GL_BGR_EXT; - } else { - assert header.pixelDepth() == 32; - format = GL.GL_BGRA_EXT; - } - - for (i = 0; i < header.height(); ++i) { - dIn.readFully(rawBuf, 0, rawWidth); - - if (header.topToBottom) - y = header.height - i - 1; // range 0 to (header.height - 1) - else - y = i; - - System.arraycopy(rawBuf, 0, data, y * rawWidth, rawBuf.length); - } - } - - public int getWidth() { return header.width(); } - public int getHeight() { return header.height(); } - - /** Returns the OpenGL format for this texture; e.g. GL.GL_BGR_EXT or GL.GL_BGRA_EXT. */ - public int getGLFormat() { return format; } - - /** Returns the raw data for this texture in the correct - (bottom-to-top) order for calls to glTexImage2D. */ - public byte[] getData() { return data; } - - public static TGAImage read(String filename) throws IOException { - LEDataInputStream dIn = new LEDataInputStream(new BufferedInputStream(new FileInputStream(filename))); - - Header header = new Header(dIn); - TGAImage res = new TGAImage(header); - res.decodeImage(dIn); - return res; - } -} |