2
* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
26
package com.sun.imageio.plugins.jpeg;
28
import java.util.Locale;
29
import javax.imageio.spi.ImageReaderSpi;
30
import javax.imageio.stream.ImageInputStream;
31
import javax.imageio.spi.IIORegistry;
32
import javax.imageio.spi.ServiceRegistry;
33
import java.io.IOException;
34
import javax.imageio.ImageReader;
35
import javax.imageio.IIOException;
37
public class JPEGImageReaderSpi extends ImageReaderSpi {
39
private static String [] writerSpiNames =
40
{"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"};
42
private boolean registered = false;
44
public JPEGImageReaderSpi() {
50
"com.sun.imageio.plugins.jpeg.JPEGImageReader",
51
new Class[] { ImageInputStream.class },
54
JPEG.nativeStreamMetadataFormatName,
55
JPEG.nativeStreamMetadataFormatClassName,
58
JPEG.nativeImageMetadataFormatName,
59
JPEG.nativeImageMetadataFormatClassName,
64
public void onRegistration(ServiceRegistry registry,
71
java.security.AccessController.doPrivileged(
72
new sun.security.action.LoadLibraryAction("jpeg"));
73
// Stuff it all into one lib for first pass
74
//java.security.AccessController.doPrivileged(
75
//new sun.security.action.LoadLibraryAction("imageioIJG"));
76
} catch (Throwable e) { // Fail on any Throwable
77
// if it can't be loaded, deregister and return
78
registry.deregisterServiceProvider(this);
86
public String getDescription(Locale locale) {
87
return "Standard JPEG Image Reader";
90
public boolean canDecodeInput(Object source) throws IOException {
91
if (!(source instanceof ImageInputStream)) {
94
ImageInputStream iis = (ImageInputStream) source;
96
// If the first two bytes are a JPEG SOI marker, it's probably
97
// a JPEG file. If they aren't, it definitely isn't a JPEG file.
98
int byte1 = iis.read();
99
int byte2 = iis.read();
101
if ((byte1 == 0xFF) && (byte2 == JPEG.SOI)) {
107
public ImageReader createReaderInstance(Object extension)
108
throws IIOException {
109
return new JPEGImageReader(this);