src/share/classes/javax/imageio/plugins/jpeg/JPEGImageWriteParam.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2005, 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


 150      * @exception IllegalStateException if the compression mode is not
 151      * <code>MODE_EXPLICIT</code>.
 152      */
 153     public boolean isCompressionLossless() {
 154         if (getCompressionMode() != MODE_EXPLICIT) {
 155             throw new IllegalStateException
 156                 ("Compression mode not MODE_EXPLICIT!");
 157         }
 158         return false;
 159     }
 160 
 161     public String[] getCompressionQualityDescriptions() {
 162         if (getCompressionMode() != MODE_EXPLICIT) {
 163             throw new IllegalStateException
 164                 ("Compression mode not MODE_EXPLICIT!");
 165         }
 166         if ((getCompressionTypes() != null) &&
 167             (getCompressionType() == null)) {
 168             throw new IllegalStateException("No compression type set!");
 169         }
 170         return (String[])qualityDescs.clone();
 171     }
 172 
 173     public float[] getCompressionQualityValues() {
 174         if (getCompressionMode() != MODE_EXPLICIT) {
 175             throw new IllegalStateException
 176                 ("Compression mode not MODE_EXPLICIT!");
 177         }
 178         if ((getCompressionTypes() != null) &&
 179             (getCompressionType() == null)) {
 180             throw new IllegalStateException("No compression type set!");
 181         }
 182         return (float[])qualityVals.clone();
 183     }
 184     /**
 185      * Returns <code>true</code> if tables are currently set.
 186      *
 187      * @return <code>true</code> if tables are present.
 188      */
 189     public boolean areTablesSet() {
 190         return (qTables != null);
 191     }
 192 
 193     /**
 194      * Sets the quantization and Huffman tables to use in encoding
 195      * abbreviated streams.  There may be a maximum of 4 tables of
 196      * each type.  These tables are ignored if tables are specified in
 197      * the metadata.  All arguments must be non-<code>null</code>.
 198      * The two arrays of Huffman tables must have the same number of
 199      * elements.  The table specifiers in the frame and scan headers
 200      * in the metadata are assumed to be equivalent to indices into
 201      * these arrays.  The argument arrays are copied by this method.
 202      *


 205      * @param ACHuffmanTables An array of Huffman table objects.
 206      *
 207      * @exception IllegalArgumentException if any of the arguments
 208      * is <code>null</code> or has more than 4 elements, or if the
 209      * numbers of DC and AC tables differ.
 210      *
 211      * @see #unsetEncodeTables
 212      */
 213     public void setEncodeTables(JPEGQTable[] qTables,
 214                                 JPEGHuffmanTable[] DCHuffmanTables,
 215                                 JPEGHuffmanTable[] ACHuffmanTables) {
 216         if ((qTables == null) ||
 217             (DCHuffmanTables == null) ||
 218             (ACHuffmanTables == null) ||
 219             (qTables.length > 4) ||
 220             (DCHuffmanTables.length > 4) ||
 221             (ACHuffmanTables.length > 4) ||
 222             (DCHuffmanTables.length != ACHuffmanTables.length)) {
 223                 throw new IllegalArgumentException("Invalid JPEG table arrays");
 224         }
 225         this.qTables = (JPEGQTable[])qTables.clone();
 226         this.DCHuffmanTables = (JPEGHuffmanTable[])DCHuffmanTables.clone();
 227         this.ACHuffmanTables = (JPEGHuffmanTable[])ACHuffmanTables.clone();
 228     }
 229 
 230     /**
 231      * Removes any quantization and Huffman tables that are currently
 232      * set.
 233      *
 234      * @see #setEncodeTables
 235      */
 236     public void unsetEncodeTables() {
 237         this.qTables = null;
 238         this.DCHuffmanTables = null;
 239         this.ACHuffmanTables = null;
 240     }
 241 
 242     /**
 243      * Returns a copy of the array of quantization tables set on the
 244      * most recent call to <code>setEncodeTables</code>, or
 245      * <code>null</code> if tables are not currently set.
 246      *
 247      * @return an array of <code>JPEGQTable</code> objects, or
 248      * <code>null</code>.
 249      *
 250      * @see #setEncodeTables
 251      */
 252     public JPEGQTable[] getQTables() {
 253         return (qTables != null) ? (JPEGQTable[])qTables.clone() : null;
 254     }
 255 
 256     /**
 257      * Returns a copy of the array of DC Huffman tables set on the
 258      * most recent call to <code>setEncodeTables</code>, or
 259      * <code>null</code> if tables are not currently set.
 260      *
 261      * @return an array of <code>JPEGHuffmanTable</code> objects, or
 262      * <code>null</code>.
 263      *
 264      * @see #setEncodeTables
 265      */
 266     public JPEGHuffmanTable[] getDCHuffmanTables() {
 267         return (DCHuffmanTables != null)
 268             ? (JPEGHuffmanTable[])DCHuffmanTables.clone()
 269             : null;
 270     }
 271 
 272     /**
 273      * Returns a copy of the array of AC Huffman tables set on the
 274      * most recent call to <code>setEncodeTables</code>, or
 275      * <code>null</code> if tables are not currently set.
 276      *
 277      * @return an array of <code>JPEGHuffmanTable</code> objects, or
 278      * <code>null</code>.
 279      *
 280      * @see #setEncodeTables
 281      */
 282     public JPEGHuffmanTable[] getACHuffmanTables() {
 283         return (ACHuffmanTables != null)
 284             ? (JPEGHuffmanTable[])ACHuffmanTables.clone()
 285             : null;
 286     }
 287 
 288     /**
 289      * Tells the writer to generate optimized Huffman tables
 290      * for the image as part of the writing process.  The
 291      * default is <code>false</code>.  If this flag is set
 292      * to <code>true</code>, it overrides any tables specified
 293      * in the metadata.  Note that this means that any image
 294      * written with this flag set to <code>true</code> will
 295      * always contain Huffman tables.
 296      *
 297      * @param optimize A boolean indicating whether to generate
 298      * optimized Huffman tables when writing.
 299      *
 300      * @see #getOptimizeHuffmanTables
 301      */
 302     public void setOptimizeHuffmanTables(boolean optimize) {
 303         optimizeHuffman = optimize;
 304     }
   1 /*
   2  * Copyright (c) 2000, 2014, 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


 150      * @exception IllegalStateException if the compression mode is not
 151      * <code>MODE_EXPLICIT</code>.
 152      */
 153     public boolean isCompressionLossless() {
 154         if (getCompressionMode() != MODE_EXPLICIT) {
 155             throw new IllegalStateException
 156                 ("Compression mode not MODE_EXPLICIT!");
 157         }
 158         return false;
 159     }
 160 
 161     public String[] getCompressionQualityDescriptions() {
 162         if (getCompressionMode() != MODE_EXPLICIT) {
 163             throw new IllegalStateException
 164                 ("Compression mode not MODE_EXPLICIT!");
 165         }
 166         if ((getCompressionTypes() != null) &&
 167             (getCompressionType() == null)) {
 168             throw new IllegalStateException("No compression type set!");
 169         }
 170         return qualityDescs.clone();
 171     }
 172 
 173     public float[] getCompressionQualityValues() {
 174         if (getCompressionMode() != MODE_EXPLICIT) {
 175             throw new IllegalStateException
 176                 ("Compression mode not MODE_EXPLICIT!");
 177         }
 178         if ((getCompressionTypes() != null) &&
 179             (getCompressionType() == null)) {
 180             throw new IllegalStateException("No compression type set!");
 181         }
 182         return qualityVals.clone();
 183     }
 184     /**
 185      * Returns <code>true</code> if tables are currently set.
 186      *
 187      * @return <code>true</code> if tables are present.
 188      */
 189     public boolean areTablesSet() {
 190         return (qTables != null);
 191     }
 192 
 193     /**
 194      * Sets the quantization and Huffman tables to use in encoding
 195      * abbreviated streams.  There may be a maximum of 4 tables of
 196      * each type.  These tables are ignored if tables are specified in
 197      * the metadata.  All arguments must be non-<code>null</code>.
 198      * The two arrays of Huffman tables must have the same number of
 199      * elements.  The table specifiers in the frame and scan headers
 200      * in the metadata are assumed to be equivalent to indices into
 201      * these arrays.  The argument arrays are copied by this method.
 202      *


 205      * @param ACHuffmanTables An array of Huffman table objects.
 206      *
 207      * @exception IllegalArgumentException if any of the arguments
 208      * is <code>null</code> or has more than 4 elements, or if the
 209      * numbers of DC and AC tables differ.
 210      *
 211      * @see #unsetEncodeTables
 212      */
 213     public void setEncodeTables(JPEGQTable[] qTables,
 214                                 JPEGHuffmanTable[] DCHuffmanTables,
 215                                 JPEGHuffmanTable[] ACHuffmanTables) {
 216         if ((qTables == null) ||
 217             (DCHuffmanTables == null) ||
 218             (ACHuffmanTables == null) ||
 219             (qTables.length > 4) ||
 220             (DCHuffmanTables.length > 4) ||
 221             (ACHuffmanTables.length > 4) ||
 222             (DCHuffmanTables.length != ACHuffmanTables.length)) {
 223                 throw new IllegalArgumentException("Invalid JPEG table arrays");
 224         }
 225         this.qTables = qTables.clone();
 226         this.DCHuffmanTables = DCHuffmanTables.clone();
 227         this.ACHuffmanTables = ACHuffmanTables.clone();
 228     }
 229 
 230     /**
 231      * Removes any quantization and Huffman tables that are currently
 232      * set.
 233      *
 234      * @see #setEncodeTables
 235      */
 236     public void unsetEncodeTables() {
 237         this.qTables = null;
 238         this.DCHuffmanTables = null;
 239         this.ACHuffmanTables = null;
 240     }
 241 
 242     /**
 243      * Returns a copy of the array of quantization tables set on the
 244      * most recent call to <code>setEncodeTables</code>, or
 245      * <code>null</code> if tables are not currently set.
 246      *
 247      * @return an array of <code>JPEGQTable</code> objects, or
 248      * <code>null</code>.
 249      *
 250      * @see #setEncodeTables
 251      */
 252     public JPEGQTable[] getQTables() {
 253         return (qTables != null) ? qTables.clone() : null;
 254     }
 255 
 256     /**
 257      * Returns a copy of the array of DC Huffman tables set on the
 258      * most recent call to <code>setEncodeTables</code>, or
 259      * <code>null</code> if tables are not currently set.
 260      *
 261      * @return an array of <code>JPEGHuffmanTable</code> objects, or
 262      * <code>null</code>.
 263      *
 264      * @see #setEncodeTables
 265      */
 266     public JPEGHuffmanTable[] getDCHuffmanTables() {
 267         return (DCHuffmanTables != null)
 268             ? DCHuffmanTables.clone()
 269             : null;
 270     }
 271 
 272     /**
 273      * Returns a copy of the array of AC Huffman tables set on the
 274      * most recent call to <code>setEncodeTables</code>, or
 275      * <code>null</code> if tables are not currently set.
 276      *
 277      * @return an array of <code>JPEGHuffmanTable</code> objects, or
 278      * <code>null</code>.
 279      *
 280      * @see #setEncodeTables
 281      */
 282     public JPEGHuffmanTable[] getACHuffmanTables() {
 283         return (ACHuffmanTables != null)
 284             ? ACHuffmanTables.clone()
 285             : null;
 286     }
 287 
 288     /**
 289      * Tells the writer to generate optimized Huffman tables
 290      * for the image as part of the writing process.  The
 291      * default is <code>false</code>.  If this flag is set
 292      * to <code>true</code>, it overrides any tables specified
 293      * in the metadata.  Note that this means that any image
 294      * written with this flag set to <code>true</code> will
 295      * always contain Huffman tables.
 296      *
 297      * @param optimize A boolean indicating whether to generate
 298      * optimized Huffman tables when writing.
 299      *
 300      * @see #getOptimizeHuffmanTables
 301      */
 302     public void setOptimizeHuffmanTables(boolean optimize) {
 303         optimizeHuffman = optimize;
 304     }