if (!new File(filename).exists()) { return null; }  ImageIcon r = null; long start = System.currentTimeMillis();  if (!GalleryFileFilter.canManipulate(filename)) { return unrecognizedThumbnail; }  if (useIM) {  ArrayList cmd = new ArrayList(); cmd.add(imPath);   cmd.add("-size"); cmd.add(d.width + "x" + d.height);  if (filterName[usage] != null && filterName[usage].length() > 0) {  cmd.add("-filter"); cmd.add(filterName[usage]); }   cmd.add(filename);   cmd.add("-resize"); cmd.add(d.width + "x" + d.height);   cmd.add("+profile"); cmd.add("*");  File temp = deterministicTempFile("thumb", "." + format[usage], tmpDir, filename + d);  if (!temp.exists()) { toDelete.add(temp);   cmd.add(temp.getPath());   int exitValue = exec((String[]) cmd.toArray(new String[0]));  if (exitValue != 0 && !imIgnoreErrorCode) { if (exitValue != -1) {  Log.log(Log.LEVEL_CRITICAL, MODULE, "ImageMagick doesn't seem to be working. Disabling"); stopUsingIM(); } } else { r = new ImageIcon(temp.getPath()); } } else { r = new ImageIcon(temp.getPath()); } }  if (!useIM && r == null) { r = javaLoad(filename, d); }  long time = System.currentTimeMillis() - start; totalTime += time; totalIter++; Log.log(Log.LEVEL_TRACE, MODULE, "Time: " + time + " - Avg: " + (totalTime / totalIter));  return r;
return load(filename, d, usage, false);
	public static ImageIcon load(String filename, Dimension d, int usage) {		if (!new File(filename).exists()) {			return null;		}		ImageIcon r = null;		long start = System.currentTimeMillis();		if (!GalleryFileFilter.canManipulate(filename)) {			return unrecognizedThumbnail;		}		if (useIM) {			//StringBuffer cmdline = new StringBuffer(imPath);			ArrayList cmd = new ArrayList();			cmd.add(imPath);			//cmdline.append(" -size ").append(d.width).append("x").append(d.height);			cmd.add("-size");			cmd.add(d.width + "x" + d.height);			if (filterName[usage] != null && filterName[usage].length() > 0) {				//cmdline.append(" -filter ").append(filterName[usage]);				cmd.add("-filter");				cmd.add(filterName[usage]);			}			//cmdline.append(" \"").append(filename).append("\"");			cmd.add(filename);			//cmdline.append(" -resize \"").append(d.width).append("x").append(d.height).append("\"");			cmd.add("-resize");			cmd.add(d.width + "x" + d.height);			//cmdline.append(" +profile \"*\" ");			cmd.add("+profile");			cmd.add("*");			File temp = deterministicTempFile("thumb", "." + format[usage], tmpDir, filename + d);			if (!temp.exists()) {				toDelete.add(temp);				//cmdline.append("\"" +temp.getPath() + "\"");				cmd.add(temp.getPath());				//int exitValue = exec(cmdline.toString());				int exitValue = exec((String[]) cmd.toArray(new String[0]));				if (exitValue != 0 && !imIgnoreErrorCode) {					if (exitValue != -1) {						// don't kill IM if it's just an InterruptedException						Log.log(Log.LEVEL_CRITICAL, MODULE, "ImageMagick doesn't seem to be working. Disabling");						stopUsingIM();					}				} else {					r = new ImageIcon(temp.getPath());				}			} else {				r = new ImageIcon(temp.getPath());			}		}		if (!useIM && r == null) {			r = javaLoad(filename, d);		}		long time = System.currentTimeMillis() - start;		totalTime += time;		totalIter++;		Log.log(Log.LEVEL_TRACE, MODULE, "Time: " + time + " - Avg: " + (totalTime / totalIter));		return r;	}