To make the image loading more flexible I'd like to propose an interface for file formats like this:
package com.jme.util;
import java.io.IOException;
import java.io.InputStream;
import com.jme.image.Image;
/**
* Interface for image loaders, classes have to implement Image load(InputStream);
* @author Galun
*
*/
public interface ImageLoader {
public Image load(InputStream is) throws IOException;
}
Texturemanager could then call the plugins like the following. In a second step the existing loaders can bemoved to the new interface design.
Index: TextureManager.java
===================================================================
RCS file: /cvs/jme/src/com/jme/util/TextureManager.java,v
retrieving revision 1.45
diff -u -r1.45 TextureManager.java
--- TextureManager.java 26 Jan 2006 10:07:57 -0000 1.45
+++ TextureManager.java 30 Apr 2006 13:55:13 -0000
@@ -70,12 +70,17 @@
final public class TextureManager {
private static HashMap m_tCache = new HashMap();
+ private static HashMap loaders = new HashMap();
public static boolean COMPRESS_BY_DEFAULT = true;
private TextureManager() {
}
+ public static void addHandler(String format, ImageLoader handler) {
+ loaders.put(format, handler);
+ }
+
/**
* <code>loadTexture</code> loads a new texture defined by the parameter
* string. Filter parameters are used to define the filtering of the
@@ -289,7 +294,10 @@
com.jme.image.Image imageData = null;
try {
String fileExt = fileName.substring(fileName.lastIndexOf('.'));
- if (".TGA".equalsIgnoreCase(fileExt)) { // TGA, direct to imageData
+ ImageLoader loader = (ImageLoader)loaders.get(fileExt);
+ if (loader != null)
+ imageData = loader.load(file.openStream());
+ else if (".TGA".equalsIgnoreCase(fileExt)) { // TGA, direct to imageData
imageData = TGALoader.loadImage(file.openStream());
} else if (".DDS".equalsIgnoreCase(fileExt)) { // DDS, direct to
// imageData