1
2 package org.freehep.graphicsio.gif;
3
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.io.BufferedOutputStream;
7 import java.io.File;
8 import java.io.FileNotFoundException;
9 import java.io.FileOutputStream;
10 import java.io.OutputStream;
11 import java.util.Properties;
12
13 import javax.imageio.spi.IIORegistry;
14 import javax.imageio.spi.ImageWriterSpi;
15
16 import org.freehep.graphicsio.ImageGraphics2D;
17 import org.freehep.util.UserProperties;
18
19
20
21
22
23
24 public class GIFGraphics2D extends ImageGraphics2D {
25
26 static {
27 try {
28 Class clazz = Class
29 .forName("org.freehep.graphicsio.gif.GIFImageWriterSpi");
30 IIORegistry.getDefaultInstance().registerServiceProvider(
31 (ImageWriterSpi)clazz.newInstance(), ImageWriterSpi.class);
32 } catch (Exception e) {
33 System.out.println(e);
34 }
35 }
36
37 private static final String rootKey = GIFGraphics2D.class.getName();
38
39 public static final String QUANTIZE_COLORS = rootKey + ".QuantizeColors";
40
41 public static final String QUANTIZE_MODE = rootKey + ".QuantizeMode";
42
43 private static final UserProperties defaultProperties = new UserProperties();
44 static {
45 defaultProperties.setProperty(QUANTIZE_COLORS, true);
46 defaultProperties.setProperty(QUANTIZE_MODE, "NeuralNetworkColor");
47 }
48
49 public static Properties getDefaultProperties() {
50 return defaultProperties;
51 }
52
53 public static void setDefaultProperties(Properties newProperties) {
54 defaultProperties.setProperties(newProperties);
55 }
56
57 public static String version = "$Revision: 9974 $";
58
59 public GIFGraphics2D(File file, Dimension size)
60 throws FileNotFoundException {
61 this(new FileOutputStream(file), size);
62 }
63
64 public GIFGraphics2D(File file, Component component)
65 throws FileNotFoundException {
66 this(new FileOutputStream(file), component);
67 }
68
69 public GIFGraphics2D(OutputStream os, Dimension size) {
70 super(new BufferedOutputStream(os), size, "gif");
71 initProperties(getDefaultProperties());
72 }
73
74 public GIFGraphics2D(OutputStream os, Component component) {
75 super(new BufferedOutputStream(os), component, "gif");
76 initProperties(getDefaultProperties());
77 }
78 }