01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.imageio.plugins.gif;
27:
28: import java.awt.image.ColorModel;
29: import java.awt.image.SampleModel;
30: import java.util.Locale;
31: import javax.imageio.ImageTypeSpecifier;
32: import javax.imageio.ImageWriter;
33: import javax.imageio.spi.ImageWriterSpi;
34: import com.sun.imageio.plugins.common.PaletteBuilder;
35:
36: public class GIFImageWriterSpi extends ImageWriterSpi {
37:
38: private static final String vendorName = "Sun Microsystems, Inc.";
39:
40: private static final String version = "1.0";
41:
42: private static final String[] names = { "gif", "GIF" };
43:
44: private static final String[] suffixes = { "gif" };
45:
46: private static final String[] MIMETypes = { "image/gif" };
47:
48: private static final String writerClassName = "com.sun.imageio.plugins.gif.GIFImageWriter";
49:
50: private static final String[] readerSpiNames = { "com.sun.imageio.plugins.gif.GIFImageReaderSpi" };
51:
52: public GIFImageWriterSpi() {
53: super (vendorName, version, names, suffixes, MIMETypes,
54: writerClassName, STANDARD_OUTPUT_TYPE, readerSpiNames,
55: true, GIFWritableStreamMetadata.NATIVE_FORMAT_NAME,
56: "com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
57: null, null, true,
58: GIFWritableImageMetadata.NATIVE_FORMAT_NAME,
59: "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
60: null, null);
61: }
62:
63: public boolean canEncodeImage(ImageTypeSpecifier type) {
64: if (type == null) {
65: throw new IllegalArgumentException("type == null!");
66: }
67:
68: SampleModel sm = type.getSampleModel();
69: ColorModel cm = type.getColorModel();
70:
71: boolean canEncode = sm.getNumBands() == 1
72: && sm.getSampleSize(0) <= 8 && sm.getWidth() <= 65535
73: && sm.getHeight() <= 65535
74: && (cm == null || cm.getComponentSize()[0] <= 8);
75:
76: if (canEncode) {
77: return true;
78: } else {
79: return PaletteBuilder.canCreatePalette(type);
80: }
81: }
82:
83: public String getDescription(Locale locale) {
84: return "Standard GIF image writer";
85: }
86:
87: public ImageWriter createWriterInstance(Object extension) {
88: return new GIFImageWriter(this);
89: }
90: }
|