KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > bmp > BMPImageWriterSpi


1 /*
2  * @(#)BMPImageWriterSpi.java 1.3 04/05/05 05:42:00
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.plugins.bmp;
9
10 import java.awt.image.DataBuffer JavaDoc;
11 import java.awt.image.SampleModel JavaDoc;
12 import java.awt.image.SinglePixelPackedSampleModel JavaDoc;
13
14 import javax.imageio.spi.ImageWriterSpi JavaDoc;
15 import javax.imageio.spi.ServiceRegistry JavaDoc;
16 import javax.imageio.spi.IIORegistry JavaDoc;
17 import javax.imageio.ImageWriter JavaDoc;
18 import javax.imageio.ImageTypeSpecifier JavaDoc;
19 import javax.imageio.IIOException JavaDoc;
20 import java.util.Locale JavaDoc;
21
22 import javax.imageio.plugins.bmp.BMPImageWriteParam JavaDoc;
23
24 public class BMPImageWriterSpi extends ImageWriterSpi JavaDoc {
25     private static String JavaDoc [] readerSpiNames =
26         {"com.sun.imageio.plugins.bmp.BMPImageReaderSpi"};
27     private static String JavaDoc[] formatNames = {"bmp", "BMP"};
28     private static String JavaDoc[] entensions = {"bmp"};
29     private static String JavaDoc[] 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 JavaDoc getDescription(Locale JavaDoc locale) {
51         return "Standard BMP Image Writer";
52     }
53
54     public void onRegistration(ServiceRegistry JavaDoc registry,
55                                Class JavaDoc<?> category) {
56         if (registered) {
57             return;
58         }
59
60         registered = true;
61     }
62
63     public boolean canEncodeImage(ImageTypeSpecifier JavaDoc type) {
64         int dataType= type.getSampleModel().getDataType();
65         if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
66             return false;
67        
68         SampleModel JavaDoc 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 JavaDoc))
78             return false;
79         
80         return true;
81     }
82
83     public ImageWriter JavaDoc createWriterInstance(Object JavaDoc extension)
84         throws IIOException JavaDoc {
85         return new BMPImageWriter(this);
86     }
87 }
88
Popular Tags