Added methods for getting normalized list of formats supported by ImageIO + minor clean-up.

This commit is contained in:
Harald Kuhr 2011-11-28 15:07:43 +01:00
parent f130e654ef
commit d1e72d1ece
3 changed files with 47 additions and 6 deletions

View File

@ -302,10 +302,21 @@ public abstract class ImageReaderBase extends ImageReader {
return IIOUtil.fakeSubsampling(pImage, pParam);
}
/**
* Tests if param has explicit destination.
*
* @param pParam the image read parameter, or {@code null}
* @return true if {@code pParam} is non-{@code null} and either its {@code getDestination},
* {@code getDestinationType} or {@code getDestinationOffset} returns a non-{@code null} value.
*/
protected static boolean hasExplicitDestination(final ImageReadParam pParam) {
return (pParam != null && (pParam.getDestination() != null || pParam.getDestinationType() != null || pParam.getDestinationOffset() != null));
}
public static void main(String[] pArgs) throws IOException {
BufferedImage image = ImageIO.read(new File(pArgs[0]));
if (image == null) {
System.err.println("Supported formats: " + Arrays.toString(ImageIO.getReaderFormatNames()));
System.err.println("Supported formats: " + Arrays.toString(IIOUtil.getNormalizedReaderFormatNames()));
System.exit(1);
}
showIt(image, pArgs[0]);
@ -347,10 +358,6 @@ public abstract class ImageReaderBase extends ImageReader {
}
}
protected static boolean hasExplicitDestination(final ImageReadParam pParam) {
return (pParam != null && (pParam.getDestination() != null || pParam.getDestinationType() != null || pParam.getDestinationOffset() != null));
}
private static class ImageLabel extends JLabel {
Paint backgroundPaint;

View File

@ -4,6 +4,7 @@ import com.twelvemonkeys.image.ImageUtil;
import com.twelvemonkeys.imageio.spi.ProviderInfo;
import javax.imageio.IIOParam;
import javax.imageio.ImageIO;
import javax.imageio.spi.IIOServiceProvider;
import javax.imageio.spi.ServiceRegistry;
import javax.imageio.stream.ImageInputStream;
@ -14,6 +15,8 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* IIOUtil
@ -146,4 +149,35 @@ public final class IIOUtil {
pRegistry.deregisterServiceProvider(pCategory.cast(pProvider), pCategory);
}
/**
* Returns a sorted array of format names, that can be read by ImageIO.
* The names are all upper-case, and contains no duplicates.
*
* @return a normalized array of {@code String}s.
* @see javax.imageio.ImageIO#getReaderFormatNames()
*/
public static String[] getNormalizedReaderFormatNames() {
return normalizeNames(ImageIO.getReaderFormatNames());
}
/**
* Returns a sorted array of format names, that can be written by ImageIO.
* The names are all upper-case, and contains no duplicates.
*
* @return a normalized array of {@code String}s.
* @see javax.imageio.ImageIO#getWriterFormatNames()
*/
public static String[] getNormalizedWriterFormatNames() {
return normalizeNames(ImageIO.getWriterFormatNames());
}
private static String[] normalizeNames(final String[] names) {
SortedSet<String> normalizedNames = new TreeSet<String>();
for (String name : names) {
normalizedNames.add(name.toUpperCase());
}
return normalizedNames.toArray(new String[normalizedNames.size()]);
}
}

View File

@ -463,7 +463,7 @@ public final class ICNSImageReader extends ImageReaderBase {
// Return blank icon + issue warning. We know the image dimensions, we just can't read the data.
processWarningOccurred(String.format(
"Cannot read %s format in type '%s' icon (no reader; installed: %s)",
format, ICNSUtil.intToStr(resource.type), Arrays.toString(ImageIO.getReaderFormatNames())
format, ICNSUtil.intToStr(resource.type), Arrays.toString(IIOUtil.getNormalizedReaderFormatNames())
));
Dimension size = resource.size();