1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.converter;
20
21 import java.util.Iterator;
22 import java.util.Set;
23 import java.util.TreeSet;
24
25 import javax.imageio.ImageIO;
26 import javax.imageio.ImageWriter;
27
28
29
30
31
32
33 public final class ImageIODetector implements ConverterDetector {
34
35
36
37
38 public ImageIODetector() {
39
40 }
41
42
43
44
45
46
47
48 public void detectConversionPlugins(final ConverterRegistry registry) {
49
50 final String[] mimeTypes = ImageIO.getWriterMIMETypes();
51
52 final Set<String> noAlphaMimeTypes = new TreeSet<String>();
53 noAlphaMimeTypes.add("image/jpeg");
54 noAlphaMimeTypes.add("image/bmp");
55
56 for (final String mimeType : mimeTypes) {
57 final Iterator<ImageWriter> iwit = ImageIO
58 .getImageWritersByMIMEType(mimeType);
59 if (iwit != null) {
60 while (iwit.hasNext()) {
61 final ImageWriter iw = iwit.next();
62 final String[] suffixes = iw.getOriginatingProvider()
63 .getFileSuffixes();
64 if (suffixes != null) {
65 for (final String suffix : suffixes) {
66 registry.registerMimeTypeAndSuffix(mimeType,
67 suffix, false);
68 }
69 }
70 registry.registerConverter(mimeType,
71 new ImageIOConverter(iw, noAlphaMimeTypes
72 .contains(mimeType)), false);
73 }
74
75 }
76
77 }
78
79 }
80 }