1 7 8 package com.sun.imageio.plugins.gif; 9 10 import java.awt.image.ColorModel ; 11 import java.awt.image.SampleModel ; 12 import java.util.Locale ; 13 import javax.imageio.ImageTypeSpecifier ; 14 import javax.imageio.ImageWriter ; 15 import javax.imageio.spi.ImageWriterSpi ; 16 import com.sun.imageio.plugins.common.PaletteBuilder; 17 18 public class GIFImageWriterSpi extends ImageWriterSpi { 19 20 private static final String vendorName = "Sun Microsystems, Inc."; 21 22 private static final String version = "1.0"; 23 24 private static final String [] names = { "gif", "GIF" }; 25 26 private static final String [] suffixes = { "gif" }; 27 28 private static final String [] MIMETypes = { "image/gif" }; 29 30 private static final String writerClassName = 31 "com.sun.imageio.plugins.gif.GIFImageWriter"; 32 33 private static final String [] 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 type) { 58 if (type == null) { 59 throw new IllegalArgumentException ("type == null!"); 60 } 61 62 SampleModel sm = type.getSampleModel(); 63 ColorModel 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 getDescription(Locale locale) { 79 return "Standard GIF image writer"; 80 } 81 82 public ImageWriter createWriterInstance(Object extension) { 83 return new GIFImageWriter(this); 84 } 85 } 86 | Popular Tags |