0N/A/*
2362N/A * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.imageio.plugins.jpeg;
0N/A
0N/Aimport javax.imageio.ImageReadParam;
0N/A
0N/A/**
0N/A * This class adds the ability to set JPEG quantization and Huffman
0N/A * tables when using the built-in JPEG reader plug-in. An instance of
0N/A * this class will be returned from the
0N/A * <code>getDefaultImageReadParam</code> methods of the built-in JPEG
0N/A * <code>ImageReader</code>.
0N/A *
0N/A * <p> The sole purpose of these additions is to allow the
0N/A * specification of tables for use in decoding abbreviated streams.
0N/A * The built-in JPEG reader will also accept an ordinary
0N/A * <code>ImageReadParam</code>, which is sufficient for decoding
0N/A * non-abbreviated streams.
0N/A *
0N/A * <p> While tables for abbreviated streams are often obtained by
0N/A * first reading another abbreviated stream containing only the
0N/A * tables, in some applications the tables are fixed ahead of time.
0N/A * This class allows the tables to be specified directly from client
0N/A * code. If no tables are specified either in the stream or in a
0N/A * <code>JPEGImageReadParam</code>, then the stream is presumed to use
0N/A * the "standard" visually lossless tables. See {@link JPEGQTable
0N/A * <code>JPEGQTable</code>} and {@link JPEGHuffmanTable
0N/A * <code>JPEGHuffmanTable</code>} for more information on the default
0N/A * tables.
0N/A *
0N/A * <p> The default <code>JPEGImageReadParam</code> returned by the
0N/A * <code>getDefaultReadParam</code> method of the builtin JPEG reader
0N/A * contains no tables. Default tables may be obtained from the table
0N/A * classes {@link JPEGQTable <code>JPEGQTable</code>} and {@link
0N/A * JPEGHuffmanTable <code>JPEGHuffmanTable</code>}.
0N/A *
0N/A * <p> If a stream does contain tables, the tables given in a
0N/A * <code>JPEGImageReadParam</code> are ignored. Furthermore, if the
0N/A * first image in a stream does contain tables and subsequent ones do
0N/A * not, then the tables given in the first image are used for all the
0N/A * abbreviated images. Once tables have been read from a stream, they
0N/A * can be overridden only by tables subsequently read from the same
0N/A * stream. In order to specify new tables, the {@link
0N/A * javax.imageio.ImageReader#setInput <code>setInput</code>} method of
0N/A * the reader must be called to change the stream.
0N/A *
0N/A * <p> Note that this class does not provide a means for obtaining the
0N/A * tables found in a stream. These may be extracted from a stream by
0N/A * consulting the <code>IIOMetadata</code> object returned by the
0N/A * reader.
0N/A *
0N/A * <p>
0N/A * For more information about the operation of the built-in JPEG plug-ins,
0N/A * see the <A HREF="../../metadata/doc-files/jpeg_metadata.html">JPEG
0N/A * metadata format specification and usage notes</A>.
0N/A *
0N/A */
0N/Apublic class JPEGImageReadParam extends ImageReadParam {
0N/A
0N/A private JPEGQTable[] qTables = null;
0N/A private JPEGHuffmanTable[] DCHuffmanTables = null;
0N/A private JPEGHuffmanTable[] ACHuffmanTables = null;
0N/A
0N/A /**
0N/A * Constructs a <code>JPEGImageReadParam</code>.
0N/A */
0N/A public JPEGImageReadParam() {
0N/A super();
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if tables are currently set.
0N/A *
0N/A * @return <code>true</code> if tables are present.
0N/A */
0N/A public boolean areTablesSet() {
0N/A return (qTables != null);
0N/A }
0N/A
0N/A /**
0N/A * Sets the quantization and Huffman tables to use in decoding
0N/A * abbreviated streams. There may be a maximum of 4 tables of
0N/A * each type. These tables are ignored once tables are
0N/A * encountered in the stream. All arguments must be
0N/A * non-<code>null</code>. The two arrays of Huffman tables must
0N/A * have the same number of elements. The table specifiers in the
0N/A * frame and scan headers in the stream are assumed to be
0N/A * equivalent to indices into these arrays. The argument arrays
0N/A * are copied by this method.
0N/A *
0N/A * @param qTables an array of quantization table objects.
0N/A * @param DCHuffmanTables an array of Huffman table objects.
0N/A * @param ACHuffmanTables an array of Huffman table objects.
0N/A *
0N/A * @exception IllegalArgumentException if any of the arguments
0N/A * is <code>null</code>, has more than 4 elements, or if the
0N/A * numbers of DC and AC tables differ.
0N/A *
0N/A * @see #unsetDecodeTables
0N/A */
0N/A public void setDecodeTables(JPEGQTable[] qTables,
0N/A JPEGHuffmanTable[] DCHuffmanTables,
0N/A JPEGHuffmanTable[] ACHuffmanTables) {
0N/A if ((qTables == null) ||
0N/A (DCHuffmanTables == null) ||
0N/A (ACHuffmanTables == null) ||
0N/A (qTables.length > 4) ||
0N/A (DCHuffmanTables.length > 4) ||
0N/A (ACHuffmanTables.length > 4) ||
0N/A (DCHuffmanTables.length != ACHuffmanTables.length)) {
0N/A throw new IllegalArgumentException
0N/A ("Invalid JPEG table arrays");
0N/A }
0N/A this.qTables = (JPEGQTable[])qTables.clone();
0N/A this.DCHuffmanTables = (JPEGHuffmanTable[])DCHuffmanTables.clone();
0N/A this.ACHuffmanTables = (JPEGHuffmanTable[])ACHuffmanTables.clone();
0N/A }
0N/A
0N/A /**
0N/A * Removes any quantization and Huffman tables that are currently
0N/A * set.
0N/A *
0N/A * @see #setDecodeTables
0N/A */
0N/A public void unsetDecodeTables() {
0N/A this.qTables = null;
0N/A this.DCHuffmanTables = null;
0N/A this.ACHuffmanTables = null;
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the array of quantization tables set on the
0N/A * most recent call to <code>setDecodeTables</code>, or
0N/A * <code>null</code> if tables are not currently set.
0N/A *
0N/A * @return an array of <code>JPEGQTable</code> objects, or
0N/A * <code>null</code>.
0N/A *
0N/A * @see #setDecodeTables
0N/A */
0N/A public JPEGQTable[] getQTables() {
0N/A return (qTables != null) ? (JPEGQTable[])qTables.clone() : null;
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the array of DC Huffman tables set on the
0N/A * most recent call to <code>setDecodeTables</code>, or
0N/A * <code>null</code> if tables are not currently set.
0N/A *
0N/A * @return an array of <code>JPEGHuffmanTable</code> objects, or
0N/A * <code>null</code>.
0N/A *
0N/A * @see #setDecodeTables
0N/A */
0N/A public JPEGHuffmanTable[] getDCHuffmanTables() {
0N/A return (DCHuffmanTables != null)
0N/A ? (JPEGHuffmanTable[])DCHuffmanTables.clone()
0N/A : null;
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the array of AC Huffman tables set on the
0N/A * most recent call to <code>setDecodeTables</code>, or
0N/A * <code>null</code> if tables are not currently set.
0N/A *
0N/A * @return an array of <code>JPEGHuffmanTable</code> objects, or
0N/A * <code>null</code>.
0N/A *
0N/A * @see #setDecodeTables
0N/A */
0N/A public JPEGHuffmanTable[] getACHuffmanTables() {
0N/A return (ACHuffmanTables != null)
0N/A ? (JPEGHuffmanTable[])ACHuffmanTables.clone()
0N/A : null;
0N/A }
0N/A}