We can't reliably make the decision as to how to load the image (FastImageIO/raw v normal) at the ResourceManager level - the path name by this point may be a file in the cache which will have lost its indicative extension. Instead, make the decision before we turn the resource path into an actual file name. This fixes YPP's current image loading issues.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@318 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -277,7 +277,7 @@ public class BundledComponentRepository
|
|||||||
// from interface ImageDataProvider
|
// from interface ImageDataProvider
|
||||||
public BufferedImage loadImage (String path) throws IOException
|
public BufferedImage loadImage (String path) throws IOException
|
||||||
{
|
{
|
||||||
return _bundle.getImageResource(path);
|
return _bundle.getImageResource(path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from interface FrameProvider
|
// from interface FrameProvider
|
||||||
@@ -357,7 +357,7 @@ public class BundledComponentRepository
|
|||||||
BufferedImage src = _imgr.getImage(getImageKey(path), zations);
|
BufferedImage src = _imgr.getImage(getImageKey(path), zations);
|
||||||
float percentageOfDataBuffer = 1;
|
float percentageOfDataBuffer = 1;
|
||||||
if (bounds != null) {
|
if (bounds != null) {
|
||||||
percentageOfDataBuffer =
|
percentageOfDataBuffer =
|
||||||
(bounds.height * bounds.width) / (float)(src.getHeight() * src.getWidth());
|
(bounds.height * bounds.width) / (float)(src.getHeight() * src.getWidth());
|
||||||
src = src.getSubimage(bounds.x, bounds.y, bounds.width, bounds.height);
|
src = src.getSubimage(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||||
}
|
}
|
||||||
@@ -485,7 +485,7 @@ public class BundledComponentRepository
|
|||||||
{
|
{
|
||||||
return _set.getTile(getTileIndex(orient, index));
|
return _set.getTile(getTileIndex(orient, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mirage getTileMirage(int orient, int index) {
|
public Mirage getTileMirage(int orient, int index) {
|
||||||
return _set.getTileMirage(getTileIndex(orient, index));
|
return _set.getTileMirage(getTileIndex(orient, index));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.io.Serializable;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
|
import com.threerings.resource.FastImageIO;
|
||||||
import com.threerings.resource.ResourceBundle;
|
import com.threerings.resource.ResourceBundle;
|
||||||
|
|
||||||
import com.threerings.media.image.ImageDataProvider;
|
import com.threerings.media.image.ImageDataProvider;
|
||||||
@@ -93,7 +94,11 @@ public class TileSetBundle extends HashIntMap
|
|||||||
public BufferedImage loadImage (String path)
|
public BufferedImage loadImage (String path)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return _bundle.getImageResource(path);
|
if (path.endsWith(FastImageIO.FILE_SUFFIX)) {
|
||||||
|
return _bundle.getImageResource(path, true);
|
||||||
|
} else {
|
||||||
|
return _bundle.getImageResource(path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom serialization process
|
// custom serialization process
|
||||||
@@ -108,7 +113,7 @@ public class TileSetBundle extends HashIntMap
|
|||||||
out.writeInt(entry.getIntKey());
|
out.writeInt(entry.getIntKey());
|
||||||
out.writeObject(entry.getValue());
|
out.writeObject(entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom unserialization process
|
// custom unserialization process
|
||||||
private void readObject (ObjectInputStream in)
|
private void readObject (ObjectInputStream in)
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ public class FileResourceBundle extends ResourceBundle
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from ResourceBundle
|
@Override // from ResourceBundle
|
||||||
public BufferedImage getImageResource (String path)
|
public BufferedImage getImageResource (String path, boolean forceFastIO)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return ResourceManager.loadImage(getResourceFile(path));
|
return ResourceManager.loadImage(getResourceFile(path), forceFastIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -54,6 +54,6 @@ public abstract class ResourceBundle
|
|||||||
* Decodes and returns the specified image resource. Returns null if no resource exists at the
|
* Decodes and returns the specified image resource. Returns null if no resource exists at the
|
||||||
* specified path.
|
* specified path.
|
||||||
*/
|
*/
|
||||||
public abstract BufferedImage getImageResource (String path)
|
public abstract BufferedImage getImageResource (String path, boolean forceFastIO)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ public class ResourceManager
|
|||||||
{
|
{
|
||||||
// first look for this resource in our default resource bundle
|
// first look for this resource in our default resource bundle
|
||||||
for (ResourceBundle bundle : _default) {
|
for (ResourceBundle bundle : _default) {
|
||||||
BufferedImage image = bundle.getImageResource(path);
|
BufferedImage image = bundle.getImageResource(path, false);
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -468,7 +468,11 @@ public class ResourceManager
|
|||||||
// fallback next to an unpacked resource file
|
// fallback next to an unpacked resource file
|
||||||
File file = getResourceFile(path);
|
File file = getResourceFile(path);
|
||||||
if (file != null && file.exists()) {
|
if (file != null && file.exists()) {
|
||||||
return loadImage(file);
|
if (path.endsWith(FastImageIO.FILE_SUFFIX)) {
|
||||||
|
return loadImage(file, true);
|
||||||
|
} else {
|
||||||
|
return loadImage(file, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// first try a locale-specific file
|
// first try a locale-specific file
|
||||||
@@ -569,12 +573,13 @@ public class ResourceManager
|
|||||||
BufferedImage image = null;
|
BufferedImage image = null;
|
||||||
// try a localized version first
|
// try a localized version first
|
||||||
if (_localePrefix != null) {
|
if (_localePrefix != null) {
|
||||||
image = bundles[ii].getImageResource(PathUtil.appendPath(_localePrefix, path));
|
image =
|
||||||
|
bundles[ii].getImageResource(PathUtil.appendPath(_localePrefix, path), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we didn't find that, try generic
|
// if we didn't find that, try generic
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
image = bundles[ii].getImageResource(path);
|
image = bundles[ii].getImageResource(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
@@ -652,14 +657,14 @@ public class ResourceManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an image from the supplied file. Supports {@link FastImageIO} files and formats
|
* Loads an image from the supplied file. Supports {@link FastImageIO} files and formats
|
||||||
* supported by {@link ImageIO}.
|
* supported by {@link ImageIO} and will load the appropriate one based on the useFastIO param.
|
||||||
*/
|
*/
|
||||||
protected static BufferedImage loadImage (File file)
|
protected static BufferedImage loadImage (File file, boolean useFastIO)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
return null;
|
return null;
|
||||||
} else if (file.getName().endsWith(FastImageIO.FILE_SUFFIX)) {
|
} else if (useFastIO) {
|
||||||
return FastImageIO.read(file);
|
return FastImageIO.read(file);
|
||||||
} else {
|
} else {
|
||||||
return ImageIO.read(file);
|
return ImageIO.read(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user