KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > gif > GIFImageWriterSpi


1 /*
2  * @(#)GIFImageWriterSpi.java 1.2 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.plugins.gif;
9
10 import java.awt.image.ColorModel JavaDoc;
11 import java.awt.image.SampleModel JavaDoc;
12 import java.util.Locale JavaDoc;
13 import javax.imageio.ImageTypeSpecifier JavaDoc;
14 import javax.imageio.ImageWriter JavaDoc;
15 import javax.imageio.spi.ImageWriterSpi JavaDoc;
16 import com.sun.imageio.plugins.common.PaletteBuilder;
17
18 public class GIFImageWriterSpi extends ImageWriterSpi JavaDoc {
19
20     private static final String JavaDoc vendorName = "Sun Microsystems, Inc.";
21
22     private static final String JavaDoc version = "1.0";
23
24     private static final String JavaDoc[] names = { "gif", "GIF" };
25
26     private static final String JavaDoc[] suffixes = { "gif" };
27
28     private static final String JavaDoc[] MIMETypes = { "image/gif" };
29
30     private static final String JavaDoc writerClassName =
31     "com.sun.imageio.plugins.gif.GIFImageWriter";
32
33     private static final String JavaDoc[] readerSpiNames = {
34         "com.sun.imageio.plugins.gif.GIFImageReaderSpi"
35     };
36
37     public GIFImageWriterSpi() {
38         super(vendorName,
39               version,
40               names,
41               suffixes,
42               MIMETypes,
43               writerClassName,
44               STANDARD_OUTPUT_TYPE,
45               readerSpiNames,
46               true,
47               GIFWritableStreamMetadata.NATIVE_FORMAT_NAME,
48               "com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
49               null, null,
50               true,
51               GIFWritableImageMetadata.NATIVE_FORMAT_NAME,
52               "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
53               null, null
54               );
55     }
56
57     public boolean canEncodeImage(ImageTypeSpecifier JavaDoc type) {
58         if (type == null) {
59             throw new IllegalArgumentException JavaDoc("type == null!");
60         }
61
62         SampleModel JavaDoc sm = type.getSampleModel();
63         ColorModel JavaDoc cm = type.getColorModel();
64
65         boolean canEncode = sm.getNumBands() == 1 &&
66             sm.getSampleSize(0) <= 8 &&
67             sm.getWidth() <= 65535 &&
68             sm.getHeight() <= 65535 &&
69             (cm == null || cm.getComponentSize()[0] <= 8);
70
71         if (canEncode) {
72             return true;
73         } else {
74             return PaletteBuilder.canCreatePalette(type);
75         }
76     }
77
78     public String JavaDoc getDescription(Locale JavaDoc locale) {
79         return "Standard GIF image writer";
80     }
81
82     public ImageWriter JavaDoc createWriterInstance(Object JavaDoc extension) {
83         return new GIFImageWriter(this);
84     }
85 }
86
Popular Tags