Revamped image loading such that the ResourceManager handles loading images
given a resource path so that it can be smart about loading from files versus streams depending on what works based based on where the resources are coming from. Also moved FastImageIO into com.threerings.resource to avoid a dependence on com.threerings.media in resource. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@310 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -36,9 +36,6 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import com.samskivert.swing.RuntimeAdjust;
|
||||
import com.samskivert.util.LRUHashMap;
|
||||
import com.samskivert.util.StringUtil;
|
||||
@@ -393,10 +390,10 @@ public class ImageManager
|
||||
throws IOException {
|
||||
// first attempt to load the image from the specified resource set
|
||||
try {
|
||||
return read(_rmgr.getImageResource(rset, path));
|
||||
return _rmgr.getImageResource(rset, path);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
// fall back to trying the classpath
|
||||
return read(_rmgr.getImageResource(path));
|
||||
return _rmgr.getImageResource(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,7 +421,7 @@ public class ImageManager
|
||||
Log.debug("Loading image " + key + ".");
|
||||
image = key.daprov.loadImage(key.path);
|
||||
if (image == null) {
|
||||
Log.warning("ImageIO.read(" + key + ") returned null.");
|
||||
Log.warning("ImageDataProvider.loadImage(" + key + ") returned null.");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -438,42 +435,6 @@ public class ImageManager
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for loading images.
|
||||
*/
|
||||
protected static BufferedImage read (ImageInputStream iis)
|
||||
throws IOException
|
||||
{
|
||||
BufferedImage image = ImageIO.read(iis);
|
||||
closeIIS(iis);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for closing image input streams.
|
||||
*/
|
||||
protected static void closeIIS (ImageInputStream iis)
|
||||
{
|
||||
if (iis == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
iis.close();
|
||||
} catch (IOException ioe) {
|
||||
// jesus fucking hoppalong cassidy christ on a polyester pogo stick!
|
||||
// ImageInputStreamImpl.close() throws a fucking IOException if it's already closed;
|
||||
// there's no way to find out if it's already closed or not, so we have to check for
|
||||
// their bullshit exception; as if we should just "trust" ImageIO.read() to close the
|
||||
// fucking input stream when it's done, especially after the goddamned fiasco with
|
||||
// PNGImageReader not closing it's fucking inflaters; for the love of humanity
|
||||
if (!"closed".equals(ioe.getMessage())) {
|
||||
Log.warning("Failure closing image input '" + iis + "'.");
|
||||
Log.logStackTrace(ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports statistics detailing the image manager cache performance and the current size of the
|
||||
* cached images.
|
||||
@@ -584,7 +545,7 @@ public class ImageManager
|
||||
/** Our default data provider. */
|
||||
protected ImageDataProvider _defaultProvider = new ImageDataProvider() {
|
||||
public BufferedImage loadImage (String path) throws IOException {
|
||||
return read(_rmgr.getImageResource(path));
|
||||
return _rmgr.getImageResource(path);
|
||||
}
|
||||
public String getIdent () {
|
||||
return "rmgr:default";
|
||||
|
||||
Reference in New Issue
Block a user