Merge from mainline.
[official-gcc.git] / libjava / classpath / javax / imageio / plugins / jpeg / JPEGImageReadParam.java
blobb570922f99ae02f8bc74e379857373fa521f3246
1 /* JPEGImageReadParam.java --
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.imageio.plugins.jpeg;
41 import javax.imageio.ImageReadParam;
43 /**
44 * The JPEGImageReadParam class is only used to set JPEG decoding
45 * tables for streams that do not provide their own tables. If a
46 * stream does not provide tables and a custom JPEGImageReadParam is
47 * not provided, then the standard JPEG tables are used from the
48 * JPEGQTable and JPEGHuffmanTable classes. If a stream does provide
49 * decoding tables then JPEGImageReadParam will be ignored.
50 * JPEGImageReadParam cannot be used to retrieve the tables from a
51 * stream. Instead, use IIOMetadata for this purpose.
53 * A JPEGImageReadParam instance is retrieved from the built-in JPEG
54 * ImageReader using the getDefaultImageReadParam method.
56 public class JPEGImageReadParam
57 extends ImageReadParam
59 private JPEGQTable[] qTables;
60 private JPEGHuffmanTable[] DCHuffmanTables;
61 private JPEGHuffmanTable[] ACHuffmanTables;
63 /**
64 * Construct a JPEGImageReadParam.
66 public JPEGImageReadParam()
68 super();
71 /**
72 * Check if the decoding tables are set.
74 * @return true if the decoding tables are set, false otherwise
76 public boolean areTablesSet()
78 // If qTables is not null then all tables are set.
79 return (qTables != null);
82 /**
83 * Set the quantization and Huffman tables that will be used to
84 * decode the stream. Copies are created of the array arguments.
85 * The number of Huffman tables must be the same in both Huffman
86 * table arrays. No argument may be null and no array may be longer
87 * than four elements.
89 * @param qTables JPEG quantization tables
90 * @param DCHuffmanTables JPEG DC Huffman tables
91 * @param ACHuffmanTables JPEG AC Huffman tables
93 * @throws IllegalArgumentException if any argument is null, if any
94 * of the arrays are longer than four elements, or if the Huffman
95 * table arrays do not have the same number of elements
97 public void setDecodeTables(JPEGQTable[] qTables,
98 JPEGHuffmanTable[] DCHuffmanTables,
99 JPEGHuffmanTable[] ACHuffmanTables)
101 if (qTables == null || DCHuffmanTables == null || ACHuffmanTables == null)
102 throw new IllegalArgumentException("null argument");
104 if (qTables.length > 4 || DCHuffmanTables.length > 4
105 || ACHuffmanTables.length > 4)
106 throw new IllegalArgumentException("argument has too many elements");
108 if (DCHuffmanTables.length != ACHuffmanTables.length)
109 throw new IllegalArgumentException("Huffman table arrays differ in length");
111 // Do a shallow copy. JPEGQTable's data is not directly
112 // modifyable since JPEGQTable.getTable returns a copy. Therefore
113 // it is safe to have multiple references to a single JPEGQTable.
114 // Likewise for JPEGHuffmanTable.
115 this.qTables = (JPEGQTable[]) qTables.clone();
116 this.DCHuffmanTables = (JPEGHuffmanTable[]) DCHuffmanTables.clone();
117 this.ACHuffmanTables = (JPEGHuffmanTable[]) ACHuffmanTables.clone();
121 * Clear the quantization and Huffman decoding tables.
123 public void unsetDecodeTables()
125 qTables = null;
126 DCHuffmanTables = null;
127 ACHuffmanTables = null;
131 * Retrieve the quantization tables.
133 * @returns an array of JPEG quantization tables
135 public JPEGQTable[] getQTables()
137 return qTables == null ? qTables : (JPEGQTable[]) qTables.clone();
141 * Retrieve the DC Huffman tables.
143 * @return an array of JPEG DC Huffman tables
145 public JPEGHuffmanTable[] getDCHuffmanTables()
147 return DCHuffmanTables == null ? DCHuffmanTables
148 : (JPEGHuffmanTable[]) DCHuffmanTables.clone();
152 * Retrieve the AC Huffman tables.
154 * @return an array of JPEG AC Huffman tables
156 public JPEGHuffmanTable[] getACHuffmanTables()
158 return ACHuffmanTables == null ? ACHuffmanTables
159 : (JPEGHuffmanTable[]) ACHuffmanTables.clone();