~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
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.jpeg;
 
27
 
 
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;
 
36
 
 
37
public class JPEGImageReaderSpi extends ImageReaderSpi {
 
38
 
 
39
    private static String [] writerSpiNames =
 
40
        {"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"};
 
41
 
 
42
    private boolean registered = false;
 
43
 
 
44
    public JPEGImageReaderSpi() {
 
45
        super(JPEG.vendor,
 
46
              JPEG.version,
 
47
              JPEG.names,
 
48
              JPEG.suffixes,
 
49
              JPEG.MIMETypes,
 
50
              "com.sun.imageio.plugins.jpeg.JPEGImageReader",
 
51
              new Class[] { ImageInputStream.class },
 
52
              writerSpiNames,
 
53
              true,
 
54
              JPEG.nativeStreamMetadataFormatName,
 
55
              JPEG.nativeStreamMetadataFormatClassName,
 
56
              null, null,
 
57
              true,
 
58
              JPEG.nativeImageMetadataFormatName,
 
59
              JPEG.nativeImageMetadataFormatClassName,
 
60
              null, null
 
61
              );
 
62
    }
 
63
 
 
64
    public void onRegistration(ServiceRegistry registry,
 
65
                               Class<?> category) {
 
66
        if (registered) {
 
67
            return;
 
68
        }
 
69
    /*
 
70
        try {
 
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);
 
79
            return;
 
80
        }
 
81
     */
 
82
 
 
83
        registered = true;
 
84
    }
 
85
 
 
86
    public String getDescription(Locale locale) {
 
87
        return "Standard JPEG Image Reader";
 
88
    }
 
89
 
 
90
    public boolean canDecodeInput(Object source) throws IOException {
 
91
        if (!(source instanceof ImageInputStream)) {
 
92
            return false;
 
93
        }
 
94
        ImageInputStream iis = (ImageInputStream) source;
 
95
        iis.mark();
 
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();
 
100
        iis.reset();
 
101
        if ((byte1 == 0xFF) && (byte2 == JPEG.SOI)) {
 
102
            return true;
 
103
        }
 
104
        return false;
 
105
    }
 
106
 
 
107
    public ImageReader createReaderInstance(Object extension)
 
108
        throws IIOException {
 
109
        return new JPEGImageReader(this);
 
110
    }
 
111
 
 
112
}