001/*
002 * $RCSfile: J2KImageReadParamJava.java,v $
003 *
004 * 
005 * Copyright (c) 2005 Sun Microsystems, Inc. All  Rights Reserved.
006 * 
007 * Redistribution and use in source and binary forms, with or without
008 * modification, are permitted provided that the following conditions
009 * are met: 
010 * 
011 * - Redistribution of source code must retain the above copyright 
012 *   notice, this  list of conditions and the following disclaimer.
013 * 
014 * - Redistribution in binary form must reproduce the above copyright
015 *   notice, this list of conditions and the following disclaimer in 
016 *   the documentation and/or other materials provided with the
017 *   distribution.
018 * 
019 * Neither the name of Sun Microsystems, Inc. or the names of 
020 * contributors may be used to endorse or promote products derived 
021 * from this software without specific prior written permission.
022 * 
023 * This software is provided "AS IS," without a warranty of any 
024 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 
025 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 
026 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
027 * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 
028 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 
029 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
030 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 
031 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
032 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
033 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
034 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
035 * POSSIBILITY OF SUCH DAMAGES. 
036 * 
037 * You acknowledge that this software is not designed or intended for 
038 * use in the design, construction, operation or maintenance of any 
039 * nuclear facility. 
040 *
041 * $Revision: 1.1 $
042 * $Date: 2005/02/11 05:01:33 $
043 * $State: Exp $
044 */
045package com.sun.media.imageioimpl.plugins.jpeg2000;
046
047import javax.imageio.ImageReadParam;
048import com.sun.media.imageio.plugins.jpeg2000.J2KImageReadParam;
049/**
050 * A subclass of <code>ImageReadParam</code> for reading images in
051 * the JPEG 2000 format.
052 *
053 * <p>The decoding parameters for JPEG 2000 are listed below:
054 *
055 * <p><table border=1>
056 * <caption><b>JPEG 2000 Plugin Decoding Parameters</b></caption>
057 * <tr><th>Parameter Name</th> <th>Description</th></tr>
058 * <tr>
059 *    <td>decodingRate</td>
060 *    <td>Specifies the decoding rate in bits per pixel (bpp) where the
061 *    number of pixels is related to the image's original size (Note:
062 *    this parameter is not affected by <code>resolution</code>).  The
063 *    codestream is either parsed (default) or truncated depending
064 *    <code>parsingEnabled</code>.  The default is <code>Double.MAX_VALUE</code>.
065 *    It means decoding with the encoding rate.
066 *    </td>
067 * </tr>
068 * <tr>
069 *    <td>resolution</td>
070 *    <td>Specifies the resolution level wanted for the decoded image
071 *    (0 means the lowest available resolution, the resolution
072 *    level gives an image with the original dimension).  If the given index
073 *    is greater than the number of available resolution levels of the
074 *    compressed image, the decoded image has the lowest available
075 *    resolution (among all tile-components).  This parameter affects only
076 *    the inverse wavelet transform and not the number of bytes read by the
077 *    codestream parser, which depends only on <code>decodingRate</code>.
078 *    </td>
079 * </tr>
080 * <tr>
081 *    <td>noROIDescaling</td>
082 *    <td>Ensures that no ROI de-scaling is performed.  Decompression is done
083 *    like there is no ROI in the image.
084 *    </td>
085 * </tr>
086 * <tr>
087 *    <td>parsingEnabled</td>
088 *    <td>Enable the parsing mode or not when the decoding rate is specified.
089 *    If it is false, the codestream is decoded as if it were truncated to
090 *    the given rate.  If it is true, the decoder creates, truncates and
091 *    decodes a virtual layer progressive codestream with the same
092 *    truncation points in each code-block.
093 *    </td>
094 * </tr>
095 * </table>
096 */
097public class J2KImageReadParamJava extends J2KImageReadParam {
098
099    /** Ensures that no ROI de-scaling is performed.  Decompression
100     *  is done like there is no ROI in the image.
101     */
102    private boolean noROIDescaling = true;
103
104    /** Enable the parsing mode or not when the decoding rate is specified .
105     *  If it is false, the codestream is decoded as if it were truncated to
106     *  the given rate.  If it is true, the decoder creates, truncates and
107     *  decodes a virtual layer progressive codestream with the same
108     *  truncation points in each code-block.
109     */
110    private boolean parsingEnabled = true;
111
112    /** Constructs a default instance of <code>J2KImageReadParamJava</code>. */
113    public J2KImageReadParamJava() {
114        super();
115    }
116
117    public J2KImageReadParamJava(ImageReadParam param) {
118        super();
119
120        // Generic settings.
121        if(param.hasController()) {
122            setController(param.getController());
123        }
124        setSourceRegion(param.getSourceRegion());
125        setSourceBands(param.getSourceBands());
126        setDestinationBands(param.getDestinationBands());
127        setDestination(param.getDestination());
128
129        setDestinationOffset(param.getDestinationOffset());
130        setSourceSubsampling(param.getSourceXSubsampling(),
131                             param.getSourceYSubsampling(),
132                             param.getSubsamplingXOffset(),
133                             param.getSubsamplingYOffset());
134        setDestinationType(param.getDestinationType());
135
136        // J2K settings.
137        J2KImageReadParam j2kParam;
138        if(param instanceof J2KImageReadParam) {
139            j2kParam = (J2KImageReadParam)param;
140        } else {
141            j2kParam = new J2KImageReadParam();
142        }
143        setDecodingRate(j2kParam.getDecodingRate());
144        setResolution(j2kParam.getResolution());
145    }
146
147    /** Sets <code>noROIDescaling</code> */
148    public void setNoROIDescaling(boolean value) {
149        this.noROIDescaling = value;
150    }
151
152    /** Gets <code>noROIDescaling</code> */
153    public boolean getNoROIDescaling() {
154        return noROIDescaling;
155    }
156
157    /** Sets <code>parsingEnabled</code> */
158    public void setParsingEnabled(boolean value) {
159        this.parsingEnabled = value;
160    }
161
162    /** Gets <code>parsingEnabled</code> */
163    public boolean getParsingEnabled() {
164        return parsingEnabled;
165    }
166}