1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 /** 18 * @author Rustem V. Rafikov 19 * @version $Revision: 1.3 $ 20 */ 21 package org.apache.harmony.x.imageio.plugins.jpeg; 22 23 import java.io.IOException; 24 import java.util.Locale; 25 import javax.imageio.ImageReader; 26 import javax.imageio.spi.ImageReaderSpi; 27 import javax.imageio.spi.ServiceRegistry; 28 import javax.imageio.stream.ImageInputStream; 29 30 public class JPEGImageReaderSpi extends ImageReaderSpi { 31 32 public JPEGImageReaderSpi() { 33 super(JPEGSpiConsts.vendorName, JPEGSpiConsts.version, 34 JPEGSpiConsts.names, JPEGSpiConsts.suffixes, 35 JPEGSpiConsts.MIMETypes, JPEGSpiConsts.readerClassName, 36 STANDARD_INPUT_TYPE, JPEGSpiConsts.writerSpiNames, 37 JPEGSpiConsts.supportsStandardStreamMetadataFormat, 38 JPEGSpiConsts.nativeStreamMetadataFormatName, 39 JPEGSpiConsts.nativeStreamMetadataFormatClassName, 40 JPEGSpiConsts.extraStreamMetadataFormatNames, 41 JPEGSpiConsts.extraStreamMetadataFormatClassNames, 42 JPEGSpiConsts.supportsStandardImageMetadataFormat, 43 JPEGSpiConsts.nativeImageMetadataFormatName, 44 JPEGSpiConsts.nativeImageMetadataFormatClassName, 45 JPEGSpiConsts.extraImageMetadataFormatNames, 46 JPEGSpiConsts.extraImageMetadataFormatClassNames); 47 } 48 49 50 @Override 51 public boolean canDecodeInput(Object source) throws IOException { 52 ImageInputStream markable = (ImageInputStream) source; 53 try { 54 markable.mark(); 55 56 byte[] signature = new byte[3]; 57 markable.seek(0); 58 markable.read(signature, 0, 3); 59 markable.reset(); 60 61 if ((signature[0] & 0xFF) == 0xFF && 62 (signature[1] & 0xFF) == JPEGConsts.SOI && 63 (signature[2] & 0xFF) == 0xFF) { // JPEG 64 return true; 65 } 66 } catch (IOException e) { 67 e.printStackTrace(); 68 } 69 return false; 70 } 71 72 @Override 73 public ImageReader createReaderInstance(Object extension) throws IOException { 74 return new JPEGImageReader(this); 75 } 76 77 @Override 78 public String getDescription(Locale locale) { 79 return "DRL JPEG decoder"; 80 } 81 82 @Override 83 public void onRegistration(ServiceRegistry registry, Class<?> category) { 84 // super.onRegistration(registry, category); 85 } 86 } 87