001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Viskov Nikolay
019: * @version $Revision$
020: */package org.apache.harmony.x.imageio.plugins.png;
021:
022: import java.awt.image.ColorModel;
023: import java.awt.image.IndexColorModel;
024: import java.io.IOException;
025: import java.util.Locale;
026:
027: import javax.imageio.ImageTypeSpecifier;
028: import javax.imageio.ImageWriter;
029: import javax.imageio.spi.ImageWriterSpi;
030:
031: import org.apache.harmony.x.imageio.plugins.ImageType;
032: import org.apache.harmony.x.imageio.plugins.PluginUtils;
033:
034: public class PNGImageWriterSpi extends ImageWriterSpi {
035:
036: public PNGImageWriterSpi() {
037: super (PluginUtils.VENDOR_NAME, PluginUtils.DEFAULT_VERSION,
038: ImageType.PNG.getNames(), ImageType.PNG.getSuffixes(),
039: ImageType.PNG.getMimeTypes(), PNGImageWriter.class
040: .getName(), STANDARD_OUTPUT_TYPE,
041: new String[] { PNGImageReaderSpi.class.getName() },
042: false,// supportsStandardStreamMetadataFormat
043: null,// nativeStreamMetadataFormatName
044: null,// nativeStreamMetadataFormatClassName
045: null,// extraStreamMetadataFormatNames
046: null,// extraStreamMetadataFormatClassNames
047: false,// supportsStandardImageMetadataFormat
048: null,// nativeImageMetadataFormatName
049: null,// nativeImageMetadataFormatClassName
050: null,// extraImageMetadataFormatNames
051: null// extraImageMetadataFormatClassNames
052: );
053: }
054:
055: @Override
056: public boolean canEncodeImage(ImageTypeSpecifier type) {
057: boolean canEncode = true;
058:
059: int numBands = type.getSampleModel().getNumBands();
060:
061: ColorModel colorModel = type.getColorModel();
062:
063: int bitDepth = colorModel.getPixelSize() / numBands;
064:
065: if (colorModel instanceof IndexColorModel) {
066: if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4
067: && bitDepth != 8) {
068: canEncode = false;
069: }
070: if (numBands != 1) {
071: canEncode = false;
072: }
073: } else if (numBands == 1) {
074: if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4
075: && bitDepth != 8 && bitDepth != 16) {
076: canEncode = false;
077: }
078: } else if (numBands == 2) {
079: if (bitDepth != 8 && bitDepth != 16) {
080: canEncode = false;
081: }
082: } else if (numBands == 3) {
083: if (bitDepth != 8 && bitDepth != 16) {
084: canEncode = false;
085: }
086: } else if (numBands == 4) {
087: if (bitDepth != 8 && bitDepth != 16) {
088: canEncode = false;
089: }
090: }
091:
092: return canEncode;
093: }
094:
095: @Override
096: public ImageWriter createWriterInstance(Object arg0)
097: throws IOException {
098: return new PNGImageWriter(this );
099: }
100:
101: @Override
102: public String getDescription(Locale arg0) {
103: return "PNG image encoder"; //$NON-NLS-1$
104: }
105:
106: }
|