1 /* 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.imageio.plugins.wbmp; 27 28 import javax.imageio.spi.ImageWriterSpi; 29 import javax.imageio.spi.ServiceRegistry; 30 import javax.imageio.spi.IIORegistry; 31 import javax.imageio.stream.ImageOutputStream; 32 import javax.imageio.ImageWriter; 33 import javax.imageio.ImageTypeSpecifier; 34 import javax.imageio.IIOException; 35 36 import java.awt.image.ColorModel; 37 import java.awt.image.IndexColorModel; 38 import java.awt.image.MultiPixelPackedSampleModel; 39 import java.awt.image.SampleModel; 40 import java.util.Locale; 41 42 public class WBMPImageWriterSpi extends ImageWriterSpi { 43 private static String [] readerSpiNames = 44 {"com.sun.imageio.plugins.wbmp.WBMPImageReaderSpi"}; 45 private static String[] formatNames = {"wbmp", "WBMP"}; 46 private static String[] entensions = {"wbmp"}; 47 private static String[] mimeType = {"image/vnd.wap.wbmp"}; 48 49 private boolean registered = false; 50 51 public WBMPImageWriterSpi() { 52 super("Oracle Corporation", 53 "1.0", 54 formatNames, 55 entensions, 56 mimeType, 57 "com.sun.imageio.plugins.wbmp.WBMPImageWriter", 58 new Class<?>[] { ImageOutputStream.class }, 59 readerSpiNames, 60 true, 61 null, null, null, null, 62 true, 63 null, null, null, null); 64 } 65 66 public String getDescription(Locale locale) { 67 return "Standard WBMP Image Writer"; 68 } 69 70 public void onRegistration(ServiceRegistry registry, 71 Class<?> category) { 72 if (registered) { 73 return; 74 } 75 76 registered = true; 77 } 78 79 public boolean canEncodeImage(ImageTypeSpecifier type) { 80 SampleModel sm = type.getSampleModel(); 81 if (!(sm instanceof MultiPixelPackedSampleModel)) 82 return false; 83 if (sm.getSampleSize(0) != 1) 84 return false; 85 86 return true; 87 } 88 89 public ImageWriter createWriterInstance(Object extension) 90 throws IIOException { 91 return new WBMPImageWriter(this); 92 } 93 }