Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 93483 invoked from network); 4 Feb 2008 12:42:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Feb 2008 12:42:08 -0000 Received: (qmail 27834 invoked by uid 500); 4 Feb 2008 12:41:59 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 27815 invoked by uid 500); 4 Feb 2008 12:41:59 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 27806 invoked by uid 99); 4 Feb 2008 12:41:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Feb 2008 04:41:59 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Feb 2008 12:41:38 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2A64A1A9832; Mon, 4 Feb 2008 04:41:46 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r618257 - in /harmony/enhanced/classlib/trunk/modules/imageio/src/main/java: javax/imageio/spi/ org/apache/harmony/x/imageio/plugins/ org/apache/harmony/x/imageio/plugins/gif/ org/apache/harmony/x/imageio/plugins/jpeg/ org/apache/harmony/x/... Date: Mon, 04 Feb 2008 12:41:40 -0000 To: commits@harmony.apache.org From: apavlenko@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080204124146.2A64A1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: apavlenko Date: Mon Feb 4 04:41:39 2008 New Revision: 618257 URL: http://svn.apache.org/viewvc?rev=618257&view=rev Log: Implemented JPEG, PNG and GIF image readers based on the AWT image loader. Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/AwtImageReader.java (with props) harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageSignature.java (with props) harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageType.java (with props) harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/PluginUtils.java (with props) harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReader.java (with props) harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReaderSpi.java (with props) Removed: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/IISDecodingImageSource.java Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReader.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReaderSpi.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageWriterSpi.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java Mon Feb 4 04:41:39 2008 @@ -22,6 +22,7 @@ import java.util.Arrays; +import org.apache.harmony.x.imageio.plugins.gif.GIFImageReaderSpi; import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi; import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi; import org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi; @@ -33,24 +34,19 @@ import org.apache.harmony.x.imageio.spi.RAFIISSpi; import org.apache.harmony.x.imageio.spi.RAFIOSSpi; -/** - * @author Rustem V. Rafikov, Viskov Nikolay - * @version $Revision: 1.3 $ - */ public final class IIORegistry extends ServiceRegistry { - private static IIORegistry instance; + private static IIORegistry instance; private static final Class[] CATEGORIES = new Class[] { - javax.imageio.spi.ImageWriterSpi.class, - javax.imageio.spi.ImageReaderSpi.class, - javax.imageio.spi.ImageInputStreamSpi.class, - //javax.imageio.spi.ImageTranscoderSpi.class, - javax.imageio.spi.ImageOutputStreamSpi.class - }; + javax.imageio.spi.ImageWriterSpi.class, + javax.imageio.spi.ImageReaderSpi.class, + javax.imageio.spi.ImageInputStreamSpi.class, + // javax.imageio.spi.ImageTranscoderSpi.class, + javax.imageio.spi.ImageOutputStreamSpi.class }; private IIORegistry() { - super(Arrays.>asList(CATEGORIES).iterator()); + super(Arrays.> asList(CATEGORIES).iterator()); registerBuiltinSpis(); registerApplicationClasspathSpis(); } @@ -60,17 +56,18 @@ registerServiceProvider(new JPEGImageReaderSpi()); registerServiceProvider(new PNGImageReaderSpi()); registerServiceProvider(new PNGImageWriterSpi()); + registerServiceProvider(new GIFImageReaderSpi()); registerServiceProvider(new FileIOSSpi()); registerServiceProvider(new FileIISSpi()); registerServiceProvider(new RAFIOSSpi()); registerServiceProvider(new RAFIISSpi()); - registerServiceProvider(new OutputStreamIOSSpi()); + registerServiceProvider(new OutputStreamIOSSpi()); registerServiceProvider(new InputStreamIISSpi()); - //-- TODO implement } public static IIORegistry getDefaultInstance() { - // TODO implement own instance for each ThreadGroup (see also ThreadLocal) + // TODO implement own instance for each ThreadGroup (see also + // ThreadLocal) synchronized (IIORegistry.class) { if (instance == null) { instance = new IIORegistry(); @@ -80,6 +77,6 @@ } public void registerApplicationClasspathSpis() { - //-- TODO implement for non-builtin plugins + // -- TODO implement for non-builtin plugins } } Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/AwtImageReader.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/AwtImageReader.java?rev=618257&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/AwtImageReader.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/AwtImageReader.java Mon Feb 4 04:41:39 2008 @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.imageio.plugins; + +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.ImageObserver; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Iterator; + +import javax.imageio.ImageReadParam; +import javax.imageio.ImageReader; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.spi.ImageReaderSpi; +import javax.imageio.stream.ImageInputStream; + +import org.apache.harmony.awt.gl.image.DecodingImageSource; +import org.apache.harmony.awt.gl.image.OffscreenImage; +import org.apache.harmony.x.imageio.internal.nls.Messages; + +/** + * This implementation is based on the image loader from the AWT module. It + * supports all the image types supported by the loader. + */ +public class AwtImageReader extends ImageReader { + + private ImageInputStream iis; + private OffscreenImage image; + + public AwtImageReader(final ImageReaderSpi imageReaderSpi) { + super(imageReaderSpi); + } + + @Override + public int getHeight(final int i) throws IOException { + return getImage(i).getHeight(new ImageObserver() { + public boolean imageUpdate(final Image img, final int infoflags, + final int x, final int y, final int width, + final int height) { + return (infoflags & HEIGHT) == 0; + } + }); + } + + @Override + public int getWidth(final int i) throws IOException { + return getImage(i).getWidth(new ImageObserver() { + public boolean imageUpdate(final Image img, final int infoflags, + final int x, final int y, final int width, + final int height) { + return (infoflags & WIDTH) == 0; + } + }); + } + + @Override + public int getNumImages(final boolean b) throws IOException { + return 1; + } + + @Override + public Iterator getImageTypes(final int i) + throws IOException { + final ColorModel model = getImage(i).getColorModel(); + final ImageTypeSpecifier[] spec = { new ImageTypeSpecifier(model, + model.createCompatibleSampleModel(1, 1)) }; + return Arrays.asList(spec).iterator(); + } + + @Override + public IIOMetadata getStreamMetadata() throws IOException { + return null; + } + + @Override + public IIOMetadata getImageMetadata(final int i) throws IOException { + return null; + } + + @Override + public BufferedImage read(final int i, final ImageReadParam imageReadParam) + throws IOException { + return getImage(i).getBufferedImage(); + } + + @Override + public void setInput(final Object input, final boolean seekForwardOnly, + final boolean ignoreMetadata) { + super.setInput(input, seekForwardOnly, ignoreMetadata); + iis = (ImageInputStream) input; + image = null; + } + + @Override + public ImageReadParam getDefaultReadParam() { + return new ImageReadParam(); + } + + private OffscreenImage getImage(final int index) throws IOException { + if (index >= getNumImages(false)) { + throw new IndexOutOfBoundsException("index >= getNumImages()"); //$NON-NLS-1$ + } + + if (image == null) { + if (iis == null) { + throw new IllegalArgumentException(Messages.getString( + "imageio.2", //$NON-NLS-1$ + "input")); //$NON-NLS-1$ + } + + final DecodingImageSource source = new IISDecodingImageSource(iis); + image = new OffscreenImage(source); + source.addConsumer(image); + source.load(); + } + + return image; + } + + private static class IISDecodingImageSource extends DecodingImageSource { + + private final InputStream is; + + IISDecodingImageSource(final ImageInputStream iis) { + is = PluginUtils.wrapIIS(iis); + } + + @Override + protected boolean checkConnection() { + return true; + } + + @Override + protected InputStream getInputStream() { + return is; + } + } +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/AwtImageReader.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageSignature.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageSignature.java?rev=618257&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageSignature.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageSignature.java Mon Feb 4 04:41:39 2008 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.imageio.plugins; + +import java.io.IOException; +import java.util.Arrays; + +import javax.imageio.stream.ImageInputStream; + +import org.apache.harmony.x.imageio.internal.nls.Messages; + +public enum ImageSignature { + JPEG(new byte[] { (byte) 0xFF, (byte) 0xD8, (byte) 0xFF }), + BMP(new byte[] { 'B', 'M' }), + GIF87a(new byte[] { 'G', 'I', 'F', '8', '7', 'a' }), + GIF89a(new byte[] { 'G', 'I', 'F', '8', '9', 'a' }), + PNG(new byte[] { (byte) 0x89, (byte) 0x50, (byte) 0x4E, (byte) 0x47, + (byte) 0x0D, (byte) 0x0A, (byte) 0x1A, (byte) 0x0A }); + + private final byte[] sig; + + ImageSignature(final byte[] sig) { + this.sig = sig; + } + + public static byte[] readSignature(final Object source, final int len) + throws IOException { + if (source == null) { + throw new IllegalArgumentException(Messages.getString("imageio.2", //$NON-NLS-1$ + "source")); //$NON-NLS-1$ + } + + if (!(source instanceof ImageInputStream)) { + return null; + } + + final ImageInputStream iis = (ImageInputStream) source; + final byte[] sig = new byte[len]; + + iis.mark(); + iis.readFully(sig); + iis.reset(); + + return sig; + } + + public byte[] getBytes() { + return sig.clone(); + } + + public boolean verify(final byte[] sig) { + return Arrays.equals(this.sig, sig); + } + + public boolean verify(final Object source) throws IOException { + return verify(readSignature(source, sig.length)); + } +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageSignature.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageType.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageType.java?rev=618257&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageType.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageType.java Mon Feb 4 04:41:39 2008 @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.imageio.plugins; + +public enum ImageType { + @SuppressWarnings("nls") + JPEG(new String[] { "jpeg", "jpg", "JPEG", "JPG" }, new String[] { + "jpeg", "jpg" }, new String[] { "image/jpeg" }), + @SuppressWarnings("nls") + BMP(new String[] { "bmp", "BMP" }, new String[] { "bmp" }, + new String[] { "image/bmp" }), + @SuppressWarnings("nls") + GIF(new String[] { "gif", "GIF" }, new String[] { "gif" }, + new String[] { "image/gif" }), + @SuppressWarnings("nls") + PNG(new String[] { "png", "PNG" }, new String[] { "png" }, + new String[] { "image/png" }); + + private final String names[]; + private final String suffixes[]; + private final String mimeTypes[]; + + ImageType(final String names[], final String suffixes[], + final String mimeTypes[]) { + this.names = names; + this.suffixes = suffixes; + this.mimeTypes = mimeTypes; + } + + public String[] getNames() { + return names.clone(); + } + + public String[] getSuffixes() { + return suffixes.clone(); + } + + public String[] getMimeTypes() { + return mimeTypes.clone(); + } +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/ImageType.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/PluginUtils.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/PluginUtils.java?rev=618257&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/PluginUtils.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/PluginUtils.java Mon Feb 4 04:41:39 2008 @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.imageio.plugins; + +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.stream.ImageInputStream; + +public class PluginUtils { + + public static final String VENDOR_NAME = "Apache Harmony"; //$NON-NLS-1$ + public static final String DEFAULT_VERSION = "1.0"; //$NON-NLS-1$ + + /** + * Wrap the specified ImageInputStream object in an InputStream. + */ + public static InputStream wrapIIS(final ImageInputStream iis) { + return new IisWrapper(iis); + } + + private static class IisWrapper extends InputStream { + + private final ImageInputStream input; + + IisWrapper(final ImageInputStream input) { + this.input = input; + } + + @Override + public int read() throws IOException { + return input.read(); + } + + @Override + public int read(final byte[] b) throws IOException { + return input.read(b); + } + + @Override + public int read(final byte[] b, final int off, final int len) + throws IOException { + return input.read(b, off, len); + } + + @Override + public long skip(final long n) throws IOException { + return input.skipBytes(n); + } + + @Override + public boolean markSupported() { + return true; + } + + @Override + public void mark(final int readlimit) { + input.mark(); + } + + @Override + public void reset() throws IOException { + input.reset(); + } + + @Override + public void close() throws IOException { + input.close(); + } + } +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/PluginUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReader.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReader.java?rev=618257&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReader.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReader.java Mon Feb 4 04:41:39 2008 @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.imageio.plugins.gif; + +import javax.imageio.spi.ImageReaderSpi; + +import org.apache.harmony.x.imageio.plugins.AwtImageReader; + +public class GIFImageReader extends AwtImageReader { + + public GIFImageReader(final ImageReaderSpi imageReaderSpi) { + super(imageReaderSpi); + } +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReader.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReaderSpi.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReaderSpi.java?rev=618257&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReaderSpi.java (added) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReaderSpi.java Mon Feb 4 04:41:39 2008 @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.imageio.plugins.gif; + +import java.io.IOException; +import java.util.Locale; + +import javax.imageio.ImageReader; +import javax.imageio.spi.ImageReaderSpi; + +import org.apache.harmony.x.imageio.plugins.ImageSignature; +import org.apache.harmony.x.imageio.plugins.ImageType; +import org.apache.harmony.x.imageio.plugins.PluginUtils; + +public class GIFImageReaderSpi extends ImageReaderSpi { + + public GIFImageReaderSpi() { + super(PluginUtils.VENDOR_NAME, PluginUtils.DEFAULT_VERSION, + ImageType.GIF.getNames(), ImageType.GIF.getSuffixes(), + ImageType.GIF.getMimeTypes(), + GIFImageReader.class.getName(), STANDARD_INPUT_TYPE, + null, false, null, null, null, null, false, null, null, + null, null); + } + + @Override + public boolean canDecodeInput(final Object source) throws IOException { + final byte[] sig = ImageSignature.readSignature(source, 6); + return ImageSignature.GIF87a.verify(sig) + || ImageSignature.GIF89a.verify(sig); + } + + @Override + public ImageReader createReaderInstance(Object extension) + throws IOException { + return new GIFImageReader(this); + } + + @Override + public String getDescription(Locale locale) { + return "GIF image decoder"; //$NON-NLS-1$ + } + +} Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/gif/GIFImageReaderSpi.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReader.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReader.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReader.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReader.java Mon Feb 4 04:41:39 2008 @@ -16,127 +16,20 @@ */ package org.apache.harmony.x.imageio.plugins.jpeg; -import java.awt.Image; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.io.IOException; -import java.util.Arrays; -import java.util.Iterator; - import javax.imageio.ImageReadParam; -import javax.imageio.ImageReader; -import javax.imageio.ImageTypeSpecifier; -import javax.imageio.metadata.IIOMetadata; import javax.imageio.plugins.jpeg.JPEGImageReadParam; import javax.imageio.spi.ImageReaderSpi; -import javax.imageio.stream.ImageInputStream; - -import org.apache.harmony.awt.gl.image.DecodingImageSource; -import org.apache.harmony.awt.gl.image.OffscreenImage; -import org.apache.harmony.x.imageio.internal.nls.Messages; -/** - * This implementation uses org.apache.harmony.awt.gl.image.JpegDecoder to read - * an image. - * - * TODO: Implement generic decoder to be used by javad2 and imageio - * - * @see org.apache.harmony.awt.gl.image.JpegDecoder - * @see org.apache.harmony.x.imageio.plugins.jpeg.IISDecodingImageSource - */ -public class JPEGImageReader extends ImageReader { +import org.apache.harmony.x.imageio.plugins.AwtImageReader; - private ImageInputStream iis; - private OffscreenImage image; +public class JPEGImageReader extends AwtImageReader { public JPEGImageReader(final ImageReaderSpi imageReaderSpi) { super(imageReaderSpi); } @Override - public int getHeight(final int i) throws IOException { - return getImage(i).getHeight(new ImageObserver() { - public boolean imageUpdate(final Image img, final int infoflags, - final int x, final int y, final int width, - final int height) { - return (infoflags & HEIGHT) == 0; - } - }); - } - - @Override - public int getWidth(final int i) throws IOException { - return getImage(i).getWidth(new ImageObserver() { - public boolean imageUpdate(final Image img, final int infoflags, - final int x, final int y, final int width, - final int height) { - return (infoflags & WIDTH) == 0; - } - }); - } - - @Override - public int getNumImages(final boolean b) throws IOException { - return 1; - } - - @Override - public Iterator getImageTypes(final int i) - throws IOException { - final ColorModel model = getImage(i).getColorModel(); - final ImageTypeSpecifier[] spec = { new ImageTypeSpecifier(model, - model.createCompatibleSampleModel(1, 1)) }; - return Arrays.asList(spec).iterator(); - } - - @Override - public IIOMetadata getStreamMetadata() throws IOException { - return null; - } - - @Override - public IIOMetadata getImageMetadata(final int i) throws IOException { - return null; - } - - @Override - public BufferedImage read(final int i, final ImageReadParam imageReadParam) - throws IOException { - return getImage(i).getBufferedImage(); - } - - @Override - public void setInput(final Object input, final boolean seekForwardOnly, - final boolean ignoreMetadata) { - super.setInput(input, seekForwardOnly, ignoreMetadata); - iis = (ImageInputStream) input; - image = null; - } - - @Override public ImageReadParam getDefaultReadParam() { return new JPEGImageReadParam(); - } - - private OffscreenImage getImage(final int index) throws IOException { - if (index >= getNumImages(false)) { - throw new IndexOutOfBoundsException("index >= getNumImages()"); //$NON-NLS-1$ - } - - if (image == null) { - if (iis == null) { - throw new IllegalArgumentException(Messages.getString( - "imageio.2", //$NON-NLS-1$ - "input")); //$NON-NLS-1$ - } - - final DecodingImageSource source = new IISDecodingImageSource(iis); - image = new OffscreenImage(source); - source.addConsumer(image); - source.load(); - } - - return image; } } Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReaderSpi.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReaderSpi.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReaderSpi.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageReaderSpi.java Mon Feb 4 04:41:39 2008 @@ -22,65 +22,48 @@ import java.io.IOException; import java.util.Locale; + import javax.imageio.ImageReader; import javax.imageio.spi.ImageReaderSpi; -import javax.imageio.spi.ServiceRegistry; -import javax.imageio.stream.ImageInputStream; + +import org.apache.harmony.x.imageio.plugins.ImageSignature; +import org.apache.harmony.x.imageio.plugins.ImageType; +import org.apache.harmony.x.imageio.plugins.PluginUtils; public class JPEGImageReaderSpi extends ImageReaderSpi { public JPEGImageReaderSpi() { - super(JPEGSpiConsts.vendorName, JPEGSpiConsts.version, - JPEGSpiConsts.names, JPEGSpiConsts.suffixes, - JPEGSpiConsts.MIMETypes, JPEGSpiConsts.readerClassName, - STANDARD_INPUT_TYPE, JPEGSpiConsts.writerSpiNames, - JPEGSpiConsts.supportsStandardStreamMetadataFormat, - JPEGSpiConsts.nativeStreamMetadataFormatName, - JPEGSpiConsts.nativeStreamMetadataFormatClassName, - JPEGSpiConsts.extraStreamMetadataFormatNames, - JPEGSpiConsts.extraStreamMetadataFormatClassNames, - JPEGSpiConsts.supportsStandardImageMetadataFormat, - JPEGSpiConsts.nativeImageMetadataFormatName, - JPEGSpiConsts.nativeImageMetadataFormatClassName, - JPEGSpiConsts.extraImageMetadataFormatNames, - JPEGSpiConsts.extraImageMetadataFormatClassNames); + super(PluginUtils.VENDOR_NAME, PluginUtils.DEFAULT_VERSION, + ImageType.JPEG.getNames(), + ImageType.JPEG.getSuffixes(), + ImageType.JPEG.getMimeTypes(), + JPEGImageReader.class.getName(), STANDARD_INPUT_TYPE, + JPEGSpiConsts.writerSpiNames, + JPEGSpiConsts.supportsStandardStreamMetadataFormat, + JPEGSpiConsts.nativeStreamMetadataFormatName, + JPEGSpiConsts.nativeStreamMetadataFormatClassName, + JPEGSpiConsts.extraStreamMetadataFormatNames, + JPEGSpiConsts.extraStreamMetadataFormatClassNames, + JPEGSpiConsts.supportsStandardImageMetadataFormat, + JPEGSpiConsts.nativeImageMetadataFormatName, + JPEGSpiConsts.nativeImageMetadataFormatClassName, + JPEGSpiConsts.extraImageMetadataFormatNames, + JPEGSpiConsts.extraImageMetadataFormatClassNames); } - @Override public boolean canDecodeInput(Object source) throws IOException { - ImageInputStream markable = (ImageInputStream) source; - try { - markable.mark(); - - byte[] signature = new byte[3]; - markable.seek(0); - markable.read(signature, 0, 3); - markable.reset(); - - if ((signature[0] & 0xFF) == 0xFF && - (signature[1] & 0xFF) == JPEGConsts.SOI && - (signature[2] & 0xFF) == 0xFF) { // JPEG - return true; - } - } catch (IOException e) { - e.printStackTrace(); - } - return false; + return ImageSignature.JPEG.verify(source); } @Override - public ImageReader createReaderInstance(Object extension) throws IOException { + public ImageReader createReaderInstance(Object extension) + throws IOException { return new JPEGImageReader(this); } @Override public String getDescription(Locale locale) { - return "DRL JPEG decoder"; - } - - @Override - public void onRegistration(ServiceRegistry registry, Class category) { - // super.onRegistration(registry, category); + return "JPEG image decoder"; //$NON-NLS-1$ } } Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageWriterSpi.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageWriterSpi.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageWriterSpi.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGImageWriterSpi.java Mon Feb 4 04:41:39 2008 @@ -20,23 +20,36 @@ */ package org.apache.harmony.x.imageio.plugins.jpeg; -import javax.imageio.spi.ImageWriterSpi; -import javax.imageio.ImageWriter; -import javax.imageio.ImageTypeSpecifier; import java.io.IOException; import java.util.Locale; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.ImageWriter; +import javax.imageio.spi.ImageWriterSpi; + +import org.apache.harmony.x.imageio.plugins.ImageType; +import org.apache.harmony.x.imageio.plugins.PluginUtils; + public class JPEGImageWriterSpi extends ImageWriterSpi { public JPEGImageWriterSpi() { - super(JPEGSpiConsts.vendorName, JPEGSpiConsts.version, - JPEGSpiConsts.names, JPEGSpiConsts.suffixes, JPEGSpiConsts.MIMETypes, - JPEGSpiConsts.writerClassName, STANDARD_OUTPUT_TYPE, - JPEGSpiConsts.readerSpiNames, JPEGSpiConsts.supportsStandardStreamMetadataFormat /*TODO: support st. metadata format*/, - JPEGSpiConsts.nativeStreamMetadataFormatName, JPEGSpiConsts.nativeStreamMetadataFormatClassName, - JPEGSpiConsts.extraStreamMetadataFormatNames, JPEGSpiConsts.extraStreamMetadataFormatClassNames, - JPEGSpiConsts.supportsStandardImageMetadataFormat, JPEGSpiConsts.nativeImageMetadataFormatName, JPEGSpiConsts.nativeImageMetadataFormatClassName, - JPEGSpiConsts.extraImageMetadataFormatNames, JPEGSpiConsts.extraImageMetadataFormatClassNames); + /* TODO: support st. metadata format */ + super(PluginUtils.VENDOR_NAME, PluginUtils.DEFAULT_VERSION, + ImageType.JPEG.getNames(), + ImageType.JPEG.getSuffixes(), + ImageType.JPEG.getMimeTypes(), + JPEGImageWriter.class.getName(), STANDARD_OUTPUT_TYPE, + JPEGSpiConsts.readerSpiNames, + JPEGSpiConsts.supportsStandardStreamMetadataFormat, + JPEGSpiConsts.nativeStreamMetadataFormatName, + JPEGSpiConsts.nativeStreamMetadataFormatClassName, + JPEGSpiConsts.extraStreamMetadataFormatNames, + JPEGSpiConsts.extraStreamMetadataFormatClassNames, + JPEGSpiConsts.supportsStandardImageMetadataFormat, + JPEGSpiConsts.nativeImageMetadataFormatName, + JPEGSpiConsts.nativeImageMetadataFormatClassName, + JPEGSpiConsts.extraImageMetadataFormatNames, + JPEGSpiConsts.extraImageMetadataFormatClassNames); } @Override @@ -51,6 +64,6 @@ @Override public String getDescription(Locale locale) { - return "DRL JPEG Encoder"; + return "JPEG image Encoder"; //$NON-NLS-1$ } } Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java Mon Feb 4 04:41:39 2008 @@ -20,38 +20,22 @@ */ package org.apache.harmony.x.imageio.plugins.jpeg; -/** - * @author Rustem V. Rafikov - * @version $Revision: 1.2 $ - */ public class JPEGSpiConsts { - private JPEGSpiConsts() {} + private JPEGSpiConsts() { + } - public static final String vendorName = "Intel Corporation"; - public static final String version = "0.1 beta"; - - static final String readerClassName = "org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReader"; - static final String writerClassName = "org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriter"; - - static final String[] names = {"jpeg", "jpg", "JPEG", "JPG"}; - static final String[] suffixes = {"jpeg", "jpg"}; - static final String[] MIMETypes = {"image/jpeg"}; - - static final String[] writerSpiNames = {"org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi"}; - static final String[] readerSpiNames = {"org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi"}; - - //-- TODO fill this stuff with correct data - static final boolean supportsStandardStreamMetadataFormat = false; - static final String nativeStreamMetadataFormatName = null; - static final String nativeStreamMetadataFormatClassName = null; - static final String[] extraStreamMetadataFormatNames = null; - static final String[] extraStreamMetadataFormatClassNames = null; - static final boolean supportsStandardImageMetadataFormat = false; - static final String nativeImageMetadataFormatName = - "org.apache.harmony.x.imageio.plugins.jpeg.MyFormatMetadata_1.0"; - static final String nativeImageMetadataFormatClassName = - "org.apache.harmony.x.imageio.plugins.jpeg.MyFormatMetadata"; - static final String[] extraImageMetadataFormatNames = null; - static final String[] extraImageMetadataFormatClassNames = null; + static final String[] writerSpiNames = { JPEGImageWriterSpi.class.getName() }; + static final String[] readerSpiNames = { JPEGImageReaderSpi.class.getName() }; + // -- TODO fill this stuff with correct data + static final boolean supportsStandardStreamMetadataFormat = false; + static final String nativeStreamMetadataFormatName = null; + static final String nativeStreamMetadataFormatClassName = null; + static final String[] extraStreamMetadataFormatNames = null; + static final String[] extraStreamMetadataFormatClassNames = null; + static final boolean supportsStandardImageMetadataFormat = false; + static final String nativeImageMetadataFormatName = null; + static final String nativeImageMetadataFormatClassName = null; + static final String[] extraImageMetadataFormatNames = null; + static final String[] extraImageMetadataFormatClassNames = null; } Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java Mon Feb 4 04:41:39 2008 @@ -15,93 +15,15 @@ * limitations under the License. */ - package org.apache.harmony.x.imageio.plugins.png; -import org.apache.harmony.awt.gl.image.DecodingImageSource; -import org.apache.harmony.awt.gl.image.OffscreenImage; -import org.apache.harmony.luni.util.NotImplementedException; -import org.apache.harmony.x.imageio.plugins.jpeg.IISDecodingImageSource; - -import javax.imageio.ImageReader; -import javax.imageio.ImageTypeSpecifier; -import javax.imageio.ImageReadParam; -import javax.imageio.plugins.jpeg.JPEGImageReadParam; import javax.imageio.spi.ImageReaderSpi; -import javax.imageio.stream.ImageInputStream; -import javax.imageio.metadata.IIOMetadata; -import java.io.IOException; -import java.util.Iterator; -import java.awt.image.BufferedImage; -public class PNGImageReader extends ImageReader { - ImageInputStream iis; +import org.apache.harmony.x.imageio.plugins.AwtImageReader; + +public class PNGImageReader extends AwtImageReader { public PNGImageReader(ImageReaderSpi imageReaderSpi) { super(imageReaderSpi); - } - - public int getNumImages(boolean allowSearch) throws IOException, NotImplementedException { - // TODO: implement - throw new NotImplementedException(); - } - - public int getWidth(int imageIndex) throws IOException, NotImplementedException { - // TODO: implement - throw new NotImplementedException(); - } - - public int getHeight(int imageIndex) throws IOException, NotImplementedException { - // TODO: implement - throw new NotImplementedException(); - } - - public Iterator getImageTypes(int imageIndex) throws IOException, NotImplementedException { - // TODO: implement - throw new NotImplementedException(); - } - - @Override - public IIOMetadata getStreamMetadata() throws IOException, NotImplementedException { - // TODO: implement - throw new NotImplementedException(); - } - - @Override - public IIOMetadata getImageMetadata(int imageIndex) throws IOException, NotImplementedException { - // TODO: implement - throw new NotImplementedException(); - } - - @Override - public BufferedImage read(int i, ImageReadParam imageReadParam) throws IOException { - if (iis == null) { - throw new IllegalArgumentException("input stream == null"); - } - - DecodingImageSource source = new IISDecodingImageSource(iis); - OffscreenImage image = new OffscreenImage(source); - source.addConsumer(image); - source.load(); - // The interrupted flag should be cleared because ImageDecoder interrupts - // current thread while decoding (due its architecture). - Thread.interrupted(); - return image.getBufferedImage(); - } - - @Override - public BufferedImage read(int i) throws IOException { - return read(i, null); - } - - @Override - public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) { - super.setInput(input, seekForwardOnly, ignoreMetadata); - iis = (ImageInputStream) input; - } - - @Override - public ImageReadParam getDefaultReadParam() { - return new ImageReadParam(); } } Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java Mon Feb 4 04:41:39 2008 @@ -15,74 +15,43 @@ * limitations under the License. */ - package org.apache.harmony.x.imageio.plugins.png; -import org.apache.harmony.x.imageio.plugins.jpeg.JPEGSpiConsts; - -import javax.imageio.spi.ImageReaderSpi; -import javax.imageio.spi.ServiceRegistry; -import javax.imageio.ImageReader; -import javax.imageio.stream.ImageInputStream; import java.io.IOException; import java.util.Locale; +import javax.imageio.ImageReader; +import javax.imageio.spi.ImageReaderSpi; + +import org.apache.harmony.x.imageio.plugins.ImageSignature; +import org.apache.harmony.x.imageio.plugins.ImageType; +import org.apache.harmony.x.imageio.plugins.PluginUtils; + public class PNGImageReaderSpi extends ImageReaderSpi { - static final String PNG_NAMES[] = new String[] {"png", "PNG"}; - static final String PNG_SUFFIXES[] = new String[] {"png"}; - static final String PNG_MIME_TYPES[] = new String[] {"image/png"}; - static final String PNG_READER_CLASS_NAME = "org.apache.harmony.x.imageio.plugins.png.PNGImageReader"; - static final String PNG_READER_SPI_NAMES[] = {"org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi"}; public PNGImageReaderSpi() { - super( - JPEGSpiConsts.vendorName, JPEGSpiConsts.version, - PNG_NAMES, PNG_SUFFIXES, - PNG_MIME_TYPES, PNG_READER_CLASS_NAME, - STANDARD_INPUT_TYPE, null, - false, null, - null, null, - null, false, - null, null, - null, null - ); + super(PluginUtils.VENDOR_NAME, PluginUtils.DEFAULT_VERSION, + ImageType.PNG.getNames(), ImageType.PNG.getSuffixes(), + ImageType.PNG.getMimeTypes(), + PNGImageReader.class.getName(), STANDARD_INPUT_TYPE, + new String[] { PNGImageWriterSpi.class.getName() }, + false, null, null, null, null, false, null, null, null, + null); } @Override - public boolean canDecodeInput(Object source) throws IOException { - ImageInputStream markable = (ImageInputStream) source; - markable.mark(); - - byte[] signature = new byte[8]; - markable.seek(0); - - int nBytes = markable.read(signature, 0, 8); - if(nBytes != 8) markable.read(signature, nBytes, 8-nBytes); - markable.reset(); - - // PNG signature: 137 80 78 71 13 10 26 10 - return (signature[0] & 0xFF) == 137 && - (signature[1] & 0xFF) == 80 && - (signature[2] & 0xFF) == 78 && - (signature[3] & 0xFF) == 71 && - (signature[4] & 0xFF) == 13 && - (signature[5] & 0xFF) == 10 && - (signature[6] & 0xFF) == 26 && - (signature[7] & 0xFF) == 10; + public boolean canDecodeInput(final Object source) throws IOException { + return ImageSignature.PNG.verify(source); } @Override - public ImageReader createReaderInstance(Object extension) throws IOException { + public ImageReader createReaderInstance(Object extension) + throws IOException { return new PNGImageReader(this); } @Override public String getDescription(Locale locale) { - return "DRL PNG decoder"; - } - - @Override - public void onRegistration(ServiceRegistry registry, Class category) { - super.onRegistration(registry, category); + return "PNG image decoder"; //$NON-NLS-1$ } } Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java?rev=618257&r1=618256&r2=618257&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java (original) +++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java Mon Feb 4 04:41:39 2008 @@ -21,7 +21,6 @@ package org.apache.harmony.x.imageio.plugins.png; import java.awt.image.ColorModel; -import java.awt.image.DataBufferByte; import java.awt.image.IndexColorModel; import java.io.IOException; import java.util.Locale; @@ -30,31 +29,27 @@ import javax.imageio.ImageWriter; import javax.imageio.spi.ImageWriterSpi; +import org.apache.harmony.x.imageio.plugins.ImageType; +import org.apache.harmony.x.imageio.plugins.PluginUtils; + public class PNGImageWriterSpi extends ImageWriterSpi { public PNGImageWriterSpi() { - super("Intel Corporation",// vendorName - "1.0",// version - new String[] { - "png", "PNG" },// names - new String[] { - "png", "PNG" },// suffixes - new String[] { - "image/png" },// MIMETypes - "org.apache.harmony.x.imageio.plugins.png.PNGImageWriter",// writerClassName - STANDARD_OUTPUT_TYPE,// outputTypes - new String[] { - "org.apache.harmony.x.imageio.plugins.png.PNGImageWriterSpi" },// readerSpiNames - false,// supportsStandardStreamMetadataFormat - null,// nativeStreamMetadataFormatName - null,// nativeStreamMetadataFormatClassName - null,// extraStreamMetadataFormatNames - null,// extraStreamMetadataFormatClassNames - false,// supportsStandardImageMetadataFormat - null,// nativeImageMetadataFormatName - null,// nativeImageMetadataFormatClassName - null,// extraImageMetadataFormatNames - null// extraImageMetadataFormatClassNames + super(PluginUtils.VENDOR_NAME, PluginUtils.DEFAULT_VERSION, + ImageType.PNG.getNames(), ImageType.PNG.getSuffixes(), + ImageType.PNG.getMimeTypes(), + PNGImageWriter.class.getName(), STANDARD_OUTPUT_TYPE, + new String[] { PNGImageReaderSpi.class.getName() }, + false,// supportsStandardStreamMetadataFormat + null,// nativeStreamMetadataFormatName + null,// nativeStreamMetadataFormatClassName + null,// extraStreamMetadataFormatNames + null,// extraStreamMetadataFormatClassNames + false,// supportsStandardImageMetadataFormat + null,// nativeImageMetadataFormatName + null,// nativeImageMetadataFormatClassName + null,// extraImageMetadataFormatNames + null// extraImageMetadataFormatClassNames ); } @@ -69,29 +64,27 @@ int bitDepth = colorModel.getPixelSize() / numBands; if (colorModel instanceof IndexColorModel) { - if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8) { + if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 + && bitDepth != 8) { canEncode = false; } if (numBands != 1) { canEncode = false; } - } - else if (numBands == 1) { - if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8 && bitDepth != 16) { + } else if (numBands == 1) { + if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 + && bitDepth != 8 && bitDepth != 16) { canEncode = false; } - } - else if (numBands == 2) { + } else if (numBands == 2) { if (bitDepth != 8 && bitDepth != 16) { canEncode = false; } - } - else if (numBands == 3) { + } else if (numBands == 3) { if (bitDepth != 8 && bitDepth != 16) { canEncode = false; } - } - else if (numBands == 4) { + } else if (numBands == 4) { if (bitDepth != 8 && bitDepth != 16) { canEncode = false; } @@ -107,7 +100,7 @@ @Override public String getDescription(Locale arg0) { - return "DRL PNG encoder"; + return "PNG image encoder"; //$NON-NLS-1$ } }