mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 20:45:29 -04:00
Added methods for getting normalized list of formats supported by ImageIO + minor clean-up.
This commit is contained in:
parent
f130e654ef
commit
d1e72d1ece
@ -302,10 +302,21 @@ public abstract class ImageReaderBase extends ImageReader {
|
|||||||
return IIOUtil.fakeSubsampling(pImage, pParam);
|
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 {
|
public static void main(String[] pArgs) throws IOException {
|
||||||
BufferedImage image = ImageIO.read(new File(pArgs[0]));
|
BufferedImage image = ImageIO.read(new File(pArgs[0]));
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
System.err.println("Supported formats: " + Arrays.toString(ImageIO.getReaderFormatNames()));
|
System.err.println("Supported formats: " + Arrays.toString(IIOUtil.getNormalizedReaderFormatNames()));
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
showIt(image, pArgs[0]);
|
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 {
|
private static class ImageLabel extends JLabel {
|
||||||
Paint backgroundPaint;
|
Paint backgroundPaint;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.twelvemonkeys.image.ImageUtil;
|
|||||||
import com.twelvemonkeys.imageio.spi.ProviderInfo;
|
import com.twelvemonkeys.imageio.spi.ProviderInfo;
|
||||||
|
|
||||||
import javax.imageio.IIOParam;
|
import javax.imageio.IIOParam;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.spi.IIOServiceProvider;
|
import javax.imageio.spi.IIOServiceProvider;
|
||||||
import javax.imageio.spi.ServiceRegistry;
|
import javax.imageio.spi.ServiceRegistry;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
@ -14,6 +15,8 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IIOUtil
|
* IIOUtil
|
||||||
@ -146,4 +149,35 @@ public final class IIOUtil {
|
|||||||
pRegistry.deregisterServiceProvider(pCategory.cast(pProvider), pCategory);
|
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()]);
|
||||||
|
}
|
||||||
}
|
}
|
@ -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.
|
// Return blank icon + issue warning. We know the image dimensions, we just can't read the data.
|
||||||
processWarningOccurred(String.format(
|
processWarningOccurred(String.format(
|
||||||
"Cannot read %s format in type '%s' icon (no reader; installed: %s)",
|
"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();
|
Dimension size = resource.size();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user