1 7 8 package com.sun.imageio.plugins.bmp; 9 10 import java.awt.image.DataBuffer ; 11 import java.awt.image.SampleModel ; 12 import java.awt.image.SinglePixelPackedSampleModel ; 13 14 import javax.imageio.spi.ImageWriterSpi ; 15 import javax.imageio.spi.ServiceRegistry ; 16 import javax.imageio.spi.IIORegistry ; 17 import javax.imageio.ImageWriter ; 18 import javax.imageio.ImageTypeSpecifier ; 19 import javax.imageio.IIOException ; 20 import java.util.Locale ; 21 22 import javax.imageio.plugins.bmp.BMPImageWriteParam ; 23 24 public class BMPImageWriterSpi extends ImageWriterSpi { 25 private static String [] readerSpiNames = 26 {"com.sun.imageio.plugins.bmp.BMPImageReaderSpi"}; 27 private static String [] formatNames = {"bmp", "BMP"}; 28 private static String [] entensions = {"bmp"}; 29 private static String [] mimeType = {"image/bmp"}; 30 31 private boolean registered = false; 32 33 public BMPImageWriterSpi() { 34 super("Sun Microsystems, Inc.", 35 "1.0", 36 formatNames, 37 entensions, 38 mimeType, 39 "com.sun.imageio.plugins.bmp.BMPImageWriter", 40 STANDARD_OUTPUT_TYPE, 41 readerSpiNames, 42 false, 43 null, null, null, null, 44 true, 45 BMPMetadata.nativeMetadataFormatName, 46 "com.sun.imageio.plugins.bmp.BMPMetadataFormat", 47 null, null); 48 } 49 50 public String getDescription(Locale locale) { 51 return "Standard BMP Image Writer"; 52 } 53 54 public void onRegistration(ServiceRegistry registry, 55 Class <?> category) { 56 if (registered) { 57 return; 58 } 59 60 registered = true; 61 } 62 63 public boolean canEncodeImage(ImageTypeSpecifier type) { 64 int dataType= type.getSampleModel().getDataType(); 65 if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT) 66 return false; 67 68 SampleModel sm = type.getSampleModel(); 69 int numBands = sm.getNumBands(); 70 if (!(numBands == 1 || numBands == 3)) 71 return false; 72 73 if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE) 74 return false; 75 76 if (dataType > DataBuffer.TYPE_BYTE && 77 !(sm instanceof SinglePixelPackedSampleModel )) 78 return false; 79 80 return true; 81 } 82 83 public ImageWriter createWriterInstance(Object extension) 84 throws IIOException { 85 return new BMPImageWriter(this); 86 } 87 } 88 | Popular Tags |