Removed obsolete image loaders.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2456 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,65 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id: ImageIOLoader.java,v 1.6 2003/01/13 22:49:46 mdb Exp $
|
|
||||||
|
|
||||||
package com.threerings.media.image;
|
|
||||||
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.imageio.ImageReader;
|
|
||||||
import javax.imageio.stream.ImageInputStream;
|
|
||||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
|
|
||||||
import com.threerings.media.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads images using the <code>ImageIO</code> services provided by J2SE
|
|
||||||
* 1.4 (and, presumably, above).
|
|
||||||
*/
|
|
||||||
public class ImageIOLoader implements ImageLoader
|
|
||||||
{
|
|
||||||
public ImageIOLoader ()
|
|
||||||
{
|
|
||||||
// we need to reference ImageIO in the constructor to force the
|
|
||||||
// classloader to attempt to load the ImageIO classes
|
|
||||||
ImageIO.setUseCache(true);
|
|
||||||
|
|
||||||
// String[] fmts = ImageIO.getReaderFormatNames();
|
|
||||||
// Log.info("Got formats " + StringUtil.toString(fmts) + ".");
|
|
||||||
|
|
||||||
Iterator iter = ImageIO.getImageReadersByFormatName("png");
|
|
||||||
if (iter.hasNext()) {
|
|
||||||
_reader = (ImageReader)iter.next();
|
|
||||||
} else {
|
|
||||||
Log.warning("Aiya! No reader.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public Image loadImage (InputStream source)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
// this seems to choke when decoding the compressed image data
|
|
||||||
// which may mean it's a JDK bug or something, but I'd like to see
|
|
||||||
// it resolved so that the image manager will work on applets
|
|
||||||
|
|
||||||
// ImageInputStream iis = null;
|
|
||||||
// // // iis = ImageIO.createImageInputStream(source);
|
|
||||||
// iis = new MemoryCacheImageInputStream(source);
|
|
||||||
|
|
||||||
// // // Log.info("Created stream " + iis + "/" + source);
|
|
||||||
// _reader.setInput(iis, true, false);
|
|
||||||
// return _reader.read(0);
|
|
||||||
|
|
||||||
// return ImageIO.read(new MemoryCacheImageInputStream(source));
|
|
||||||
return ImageIO.read(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ImageReader _reader;
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id: ToolkitLoader.java,v 1.3 2003/01/08 04:09:02 mdb Exp $
|
|
||||||
|
|
||||||
package com.threerings.media.image;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.MediaTracker;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import org.apache.commons.io.StreamUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads images using the default AWT toolkit (for compatibility with
|
|
||||||
* pre-1.4 JVMs).
|
|
||||||
*/
|
|
||||||
public class ToolkitLoader implements ImageLoader
|
|
||||||
{
|
|
||||||
public ToolkitLoader (Component context)
|
|
||||||
{
|
|
||||||
// do something more informative than NPE if we're misconfigured
|
|
||||||
if (context == null) {
|
|
||||||
String errmsg = "Toolkit image loader constructed without a " +
|
|
||||||
"context via which we can create a MediaTracker. If the " +
|
|
||||||
"image manager may fall back to using the Toolkit image " +
|
|
||||||
"loader (like it just did), then you have to provide a " +
|
|
||||||
"component instance for it at construct time. Thanks and " +
|
|
||||||
"have a nice day.";
|
|
||||||
throw new RuntimeException(errmsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
_toolkit = context.getToolkit();
|
|
||||||
_tracker = new MediaTracker(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public Image loadImage (InputStream source)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
byte[] data = StreamUtils.streamAsBytes(source, READ_BUFFER_SIZE);
|
|
||||||
Image image = _toolkit.createImage(data);
|
|
||||||
|
|
||||||
// we now have to wait for the image to finish decoding (this all
|
|
||||||
// apparently happens on another thread. yay!)
|
|
||||||
_tracker.addImage(image, 0);
|
|
||||||
|
|
||||||
// if something goes horribly awry, we don't want to go into an
|
|
||||||
// infinite loop, so we bound the number of times we'll allow
|
|
||||||
// ourselves to be interrupted and loop
|
|
||||||
boolean done = false;
|
|
||||||
for (int i = 0; (i < 1000) && !done; i++) {
|
|
||||||
try {
|
|
||||||
_tracker.waitForAll();
|
|
||||||
done = true;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// loop back around
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Our AWT toolkit which we use to create images. */
|
|
||||||
protected Toolkit _toolkit;
|
|
||||||
|
|
||||||
/** Used to wait for images to load. */
|
|
||||||
protected MediaTracker _tracker;
|
|
||||||
|
|
||||||
/** The size of the read buffer used to load the image data. */
|
|
||||||
protected static final int READ_BUFFER_SIZE = 4096;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user