1/*
2 * Copyright (c) 2000, 2010, 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
26package com.sun.imageio.plugins.gif;
27
28import java.io.IOException;
29import java.util.Locale;
30import java.util.Iterator;
31import javax.imageio.ImageReader;
32import javax.imageio.metadata.IIOMetadataFormat;
33import javax.imageio.metadata.IIOMetadataFormatImpl;
34import javax.imageio.spi.ImageReaderSpi;
35import javax.imageio.stream.ImageInputStream;
36
37public class GIFImageReaderSpi extends ImageReaderSpi {
38
39    private static final String vendorName = "Oracle Corporation";
40
41    private static final String version = "1.0";
42
43    private static final String[] names = { "gif", "GIF" };
44
45    private static final String[] suffixes = { "gif" };
46
47    private static final String[] MIMETypes = { "image/gif" };
48
49    private static final String readerClassName =
50        "com.sun.imageio.plugins.gif.GIFImageReader";
51
52    private static final String[] writerSpiNames = {
53        "com.sun.imageio.plugins.gif.GIFImageWriterSpi"
54    };
55
56    public GIFImageReaderSpi() {
57        super(vendorName,
58              version,
59              names,
60              suffixes,
61              MIMETypes,
62              readerClassName,
63              new Class<?>[] { ImageInputStream.class },
64              writerSpiNames,
65              true,
66              GIFStreamMetadata.nativeMetadataFormatName,
67              "com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
68              null, null,
69              true,
70              GIFImageMetadata.nativeMetadataFormatName,
71              "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
72              null, null
73              );
74    }
75
76    public String getDescription(Locale locale) {
77        return "Standard GIF image reader";
78    }
79
80    public boolean canDecodeInput(Object input) throws IOException {
81        if (!(input instanceof ImageInputStream)) {
82            return false;
83        }
84
85        ImageInputStream stream = (ImageInputStream)input;
86        byte[] b = new byte[6];
87        stream.mark();
88        stream.readFully(b);
89        stream.reset();
90
91        return b[0] == 'G' && b[1] == 'I' && b[2] == 'F' && b[3] == '8' &&
92            (b[4] == '7' || b[4] == '9') && b[5] == 'a';
93    }
94
95    public ImageReader createReaderInstance(Object extension) {
96        return new GIFImageReader(this);
97    }
98
99}
100