applied DarkProphets patch for better error handling and more types
This commit is contained in:
parent
1b453d6e10
commit
8904f18bae
|
@ -447,53 +447,79 @@ public class IL {
|
||||||
* @param filename File to determine type for
|
* @param filename File to determine type for
|
||||||
* @return IL type, or IL_TYPE_UNKNOWN if undeterminable
|
* @return IL type, or IL_TYPE_UNKNOWN if undeterminable
|
||||||
*/
|
*/
|
||||||
public static int getILType(String filename) {
|
public static int ilGetType(String extension) {
|
||||||
int index = filename.lastIndexOf('.');
|
// Save having to use equalsIgnoreCase all the time
|
||||||
if (index != -1) {
|
extension = extension.toLowerCase();
|
||||||
String extension = filename.substring(index + 1);
|
int type = IL_TYPE_UNKNOWN;
|
||||||
if (extension.equalsIgnoreCase("bmp")) {
|
|
||||||
return IL_BMP;
|
if (extension.equals("bmp")) {
|
||||||
} else if (extension.equalsIgnoreCase("cut")) {
|
type = IL_BMP;
|
||||||
return IL_CUT;
|
} else if (extension.equals("cut")) {
|
||||||
} else if (extension.equalsIgnoreCase("gif")) {
|
type = IL_CUT;
|
||||||
return IL_GIF;
|
} else if (extension.equals("gif")) {
|
||||||
} else if (extension.equalsIgnoreCase("ico")) {
|
type = IL_GIF;
|
||||||
return IL_ICO;
|
} else if (extension.equals("ico")) {
|
||||||
} else if (extension.equalsIgnoreCase("jpg")
|
type = IL_ICO;
|
||||||
|| extension.equalsIgnoreCase("jpeg")
|
} else if (extension.equals("jpg")) {
|
||||||
|| extension.equalsIgnoreCase("jpe")) {
|
type = IL_JPG;
|
||||||
return IL.IL_JPG;
|
} else if (extension.equals("lif")) {
|
||||||
} else if (extension.equalsIgnoreCase("lif")) {
|
type = IL_LIF;
|
||||||
return IL_LIF;
|
} else if (extension.equals("mng")) {
|
||||||
} else if (extension.equalsIgnoreCase("mng")) {
|
type = IL_MNG;
|
||||||
return IL_MNG;
|
} else if (extension.equals("pcd")) {
|
||||||
} else if (extension.equalsIgnoreCase("pcd")) {
|
type = IL_PCD;
|
||||||
return IL_PCD;
|
} else if (extension.equals("pcx")) {
|
||||||
} else if (extension.equalsIgnoreCase("pcx")) {
|
type = IL_PCX;
|
||||||
return IL_PCX;
|
} else if (extension.equals("pic")) {
|
||||||
} else if (extension.equalsIgnoreCase("pic")) {
|
type = IL_PIC;
|
||||||
return IL_PIC;
|
} else if (extension.equals("png")) {
|
||||||
} else if (extension.equalsIgnoreCase("png")) {
|
type = IL_PNG;
|
||||||
return IL_PNG;
|
} else if (extension.equals("pbm") || extension.equals("pgm")
|
||||||
} else if (extension.equalsIgnoreCase("pbm") || extension.equalsIgnoreCase("pgm")
|
|| extension.equals("ppm")) {
|
||||||
|| extension.equalsIgnoreCase("ppm")) {
|
type = IL_PNM;
|
||||||
return IL_PNM;
|
} else if (extension.equals("psd")) {
|
||||||
} else if (extension.equalsIgnoreCase("psd")) {
|
type = IL_PSD;
|
||||||
return IL_PSD;
|
} else if (extension.equals("psp")) {
|
||||||
} else if (extension.equalsIgnoreCase("psp")) {
|
type = IL_PSP;
|
||||||
return IL_PSP;
|
} else if (extension.equals("bw") || extension.equals("rgb")
|
||||||
} else if (extension.equalsIgnoreCase("bw") || extension.equalsIgnoreCase("rgb")
|
|| extension.equals("rgba") || extension.equals("sgi")) {
|
||||||
|| extension.equalsIgnoreCase("rgba") || extension.equalsIgnoreCase("sgi")) {
|
type = IL_SGI;
|
||||||
return IL_SGI;
|
} else if (extension.equals("tga")) {
|
||||||
} else if (extension.equalsIgnoreCase("tga")) {
|
type = IL_TGA;
|
||||||
return IL_TGA;
|
} else if (extension.equals("tif") || extension.equals("tiff")) {
|
||||||
} else if (extension.equalsIgnoreCase("tif") || extension.equalsIgnoreCase("tiff")) {
|
type = IL_TIF;
|
||||||
return IL_TIF;
|
} else if (extension.equals("dds")) {
|
||||||
}
|
type = IL_DDS;
|
||||||
}
|
} else if (extension.equals("raw")) {
|
||||||
return IL_TYPE_UNKNOWN;
|
type = IL_RAW;
|
||||||
|
} else if (extension.equals("lbm")) {
|
||||||
|
type = IL_LBM;
|
||||||
|
} else if (extension.equals("jng")) {
|
||||||
|
type = IL_JNG;
|
||||||
|
} else if (extension.equals("wal")) {
|
||||||
|
type = IL_WAL;
|
||||||
|
} else if (extension.equals("pix")) {
|
||||||
|
type = IL_PIX;
|
||||||
|
} else if (extension.equals("mdl")) {
|
||||||
|
type = IL_MDL;
|
||||||
|
} else if (extension.equals("exif")) {
|
||||||
|
type = IL_EXIF;
|
||||||
|
} else if (extension.equals("oil")) {
|
||||||
|
type = IL_OIL;
|
||||||
|
} else if (extension.equals("dcx")) {
|
||||||
|
type = IL_DCX;
|
||||||
|
} else if (extension.equals("pxr")) {
|
||||||
|
type = IL_PXR;
|
||||||
|
} else if (extension.equals("xpm")) {
|
||||||
|
type = IL_XPM;
|
||||||
|
} else if (extension.equals("pal")) {
|
||||||
|
type = IL_JASC_PAL;
|
||||||
|
} else if (extension.equals("h")) {
|
||||||
|
type = IL_CHEAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an image from the specified url
|
* Loads an image from the specified url
|
||||||
|
@ -501,20 +527,16 @@ public class IL {
|
||||||
* @param url URL to load from
|
* @param url URL to load from
|
||||||
* @return true if image was loaded
|
* @return true if image was loaded
|
||||||
*/
|
*/
|
||||||
public static boolean ilLoadFromURL(URL url) {
|
public static boolean ilLoadFromURL(URL url) throws IOException {
|
||||||
boolean result = false;
|
int type = IL_TYPE_UNKNOWN;
|
||||||
|
|
||||||
String file = url.toString();
|
String file = url.toString();
|
||||||
|
int index = file.lastIndexOf('.');
|
||||||
// read stream
|
if (index != -1) {
|
||||||
try {
|
String extension = file.substring(index + 1);
|
||||||
result = ilLoadFromStream(url.openStream(), getILType(file));
|
type = ilGetType(extension);
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result = false;
|
|
||||||
}
|
}
|
||||||
|
return ilLoadFromStream(url.openStream(), type);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -524,7 +546,7 @@ public class IL {
|
||||||
* @param type Type of image to expect
|
* @param type Type of image to expect
|
||||||
* @return true if image was loaded
|
* @return true if image was loaded
|
||||||
*/
|
*/
|
||||||
public static boolean ilLoadFromStream(InputStream stream, int type) {
|
public static boolean ilLoadFromStream(InputStream stream, int type) throws IOException {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int lastRead = 0;
|
int lastRead = 0;
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
|
@ -542,8 +564,10 @@ public class IL {
|
||||||
lump.flip();
|
lump.flip();
|
||||||
result = ilLoadL(type, lump);
|
result = ilLoadL(type, lump);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
try {
|
||||||
result = false;
|
buf.close();
|
||||||
|
} catch (IOException f ) {}
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -70,7 +70,12 @@ public class BasicTest {
|
||||||
System.out.println("error = " + ILU.iluErrorString(IL.ilGetError()));
|
System.out.println("error = " + ILU.iluErrorString(IL.ilGetError()));
|
||||||
URL imageURL = BasicTest.class.getResource("/res/ILtest.tga");
|
URL imageURL = BasicTest.class.getResource("/res/ILtest.tga");
|
||||||
System.out.println("ilLoadFromURL " + imageURL);
|
System.out.println("ilLoadFromURL " + imageURL);
|
||||||
|
try {
|
||||||
System.out.println("load lump = " + IL.ilLoadFromURL(imageURL));
|
System.out.println("load lump = " + IL.ilLoadFromURL(imageURL));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
System.out.println("error = " + ILU.iluErrorString(IL.ilGetError()));
|
System.out.println("error = " + ILU.iluErrorString(IL.ilGetError()));
|
||||||
int newIm = IL.ilCloneCurImage();
|
int newIm = IL.ilCloneCurImage();
|
||||||
IL.ilCopyImage(im.get(0));
|
IL.ilCopyImage(im.get(0));
|
||||||
|
|
Loading…
Reference in New Issue