All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jaiimageio.jpeg2000.J2KImageWriteParam Maven / Gradle / Ivy

Go to download

JPEG2000 support for Java Advanced Imaging Image I/O Tools API core. This module is licensed under the [JJ2000 license](LICENSE.txt) and is therefore NOT compatible with the GPL 3 license. It should be compatible with the LGPL 2.1 license.

There is a newer version: 1.4.0
Show newest version
/*
 * $RCSfile: J2KImageWriteParam.java,v $
 *
 * 
 * Copyright (c) 2005 Sun Microsystems, Inc. All  Rights Reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met: 
 * 
 * - Redistribution of source code must retain the above copyright 
 *   notice, this  list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in 
 *   the documentation and/or other materials provided with the
 *   distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of 
 * contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any 
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 
 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 
 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 
 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES. 
 * 
 * You acknowledge that this software is not designed or intended for 
 * use in the design, construction, operation or maintenance of any 
 * nuclear facility. 
 *
 * $Revision: 1.2 $
 * $Date: 2006/09/20 23:23:30 $
 * $State: Exp $
 */
package com.github.jaiimageio.jpeg2000;

import java.util.Locale;

import javax.imageio.ImageWriteParam;

/**
 * A subclass of ImageWriteParam for writing images in
 * the JPEG 2000 format.
 *
 * 

JPEG 2000 plugin supports to losslessly or lossy compress gray-scale, * RGB, and RGBA images with byte, unsigned short or short data type. It also * supports losslessly compress bilevel, and 8-bit color indexed images. The * result data is in the of JP2 format -- JPEG 2000 Part 1 or baseline format. * *

The parameters for encoding JPEG 2000 are listed in the following table: * *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
JPEG 2000 Plugin Decoding Parameters
Parameter Name Description
numDecompositionLevels The number of decomposition levels to generate. This value must * be in the range * 0 ≤ numDecompositionLevels ≤ 32 * . The default value is 5. Note that the number * of resolution levels is * numDecompositionLevels + 1. * The number of decomposition levels is constant across * all components and all tiles. *
encodingRate The bitrate in bits-per-pixel for encoding. Should be set when * lossy compression scheme is used. With the default value * Double.MAX_VALUE, a lossless compression will be done. *
lossless Indicates using the lossless scheme or not. It is equivalent to * use reversible quantization and 5x3 integer wavelet filters. The * default is true. *
componentTransformation Specifies to utilize the component transformation on some tiles. * If the wavelet transform is reversible (w5x3 filter), the Reversible * Component Transformation (RCT) is applied. If not reversible * (w9x7 filter), the Irreversible Component Transformation (ICT) is used. *
filters Specifies which wavelet filters to use for the specified * tile-components. JPEG 2000 part I only supports w5x3 and w9x7 filters. *
codeBlockSize Specifies the maximum code-block size to use for tile-component. * The maximum width and height is 1024, however the block size * (i.e. width x height) must not exceed 4096. The minimum width and * height is 4. The default values are (64, 64). *
progressionType Specifies which type of progression should be used when generating * the codestream. *

The format is ont of the progression types defined below: * *

res : Resolution-Layer-Component-Position *

layer: Layer-Resolution-Component-Position *

res-pos: Resolution-Position-Component-Layer *

pos-comp: Position-Component-Resolution-Layer *

comp-pos: Component-Position-Resolution-Layer *

SOPSpecifies whether start of packet (SOP) markers should be used. * true enables, false disables it. The default value is false. *
EPHSpecifies whether end of packet header (EPH) markers should be used. * true enables, false disables it. The default value is false. *
writeCodeStreamOnlySpecifies whether write only the jpeg2000 code stream, i.e, no any * box is written. The default value is false. *
*/ public class J2KImageWriteParam extends ImageWriteParam { /** The filter for lossy compression. */ public static final String FILTER_97 = "w9x7"; /** The filter for lossless compression. */ public static final String FILTER_53 = "w5x3"; /** * The number of decomposition levels. */ private int numDecompositionLevels = 5; /** * The bitrate in bits-per-pixel for encoding. Should be set when lossy * compression scheme is used. The default is * Double.MAX_VALUE. */ private double encodingRate = Double.MAX_VALUE; /** * Indicates using the lossless scheme or not. It is equivalent to * use reversible quantization and 5x3 integer wavelet filters. */ private boolean lossless = true; /** Specifies to utilize the component transformation with some tiles. * If the wavelet transform is reversible (w5x3 filter), the * Reversible Component Transformation (RCT) is applied. If not reversible * (w9x7 filter), the Irreversible Component Transformation (ICT) * is used. */ private boolean componentTransformation = true; /** Specifies which filters to use for the specified tile-components. * JPEG 2000 part I only supports w5x3 and w9x7 filters. */ private String filter = FILTER_53; /** Specifies the maximum code-block size to use for tile-component. * The maximum width and height is 1024, however the image area * (i.e. width x height) must not exceed 4096. The minimum * width and height is 4. Default: 64 64. */ private int[] codeBlockSize = new int[]{64, 64}; /** See above. */ private String progressionType = "layer"; /** Specifies whether end of packet header (EPH) markers should be used. * true enables, false disables it. Default: false. */ private boolean EPH = false; /** Specifies whether start of packet (SOP) markers should be used. * true enables, false disables it. Default: false. */ private boolean SOP = false; /** Specifies whether write only the jpeg2000 code stream, i.e, no any * box is written. The default value is false. */ private boolean writeCodeStreamOnly = false; /** * Constructor which sets the Locale. * * @param locale a Locale to be used to localize * compression type names and quality descriptions, or * null. */ public J2KImageWriteParam(Locale locale) { super(locale); setDefaults(); } /** * Constructs a J2KImageWriteParam object with default * values for all parameters. */ public J2KImageWriteParam() { super(); setDefaults(); } /** Set source */ private void setDefaults() { // override the params in the super class canOffsetTiles = true; canWriteTiles = true; canOffsetTiles = true; compressionTypes = new String[] {"JPEG2000"}; canWriteCompressed = true; tilingMode = MODE_EXPLICIT; } /** * Sets numDecompositionLevels. * * @param numDecompositionLevels the number of decomposition levels. * @throws IllegalArgumentException if numDecompositionLevels * is negative or greater than 32. * @see #getNumDecompositionLevels */ public void setNumDecompositionLevels(int numDecompositionLevels) { if(numDecompositionLevels < 0 || numDecompositionLevels > 32) { throw new IllegalArgumentException ("numDecompositionLevels < 0 || numDecompositionLevels > 32"); } this.numDecompositionLevels = numDecompositionLevels; } /** * Gets numDecompositionLevels. * * @return the number of decomposition levels. * @see #setNumDecompositionLevels */ public int getNumDecompositionLevels() { return numDecompositionLevels; } /** * Sets encodingRate. * * @param rate the encoding rate in bits-per-pixel. * @see #getEncodingRate() */ public void setEncodingRate(double rate) { this.encodingRate = rate; if (encodingRate != Double.MAX_VALUE) { lossless = false; filter = FILTER_97; } else { lossless = true; filter = FILTER_53; } } /** * Gets encodingRate. * * @return the encoding rate in bits-per-pixel. * @see #setEncodingRate(double) */ public double getEncodingRate() { return encodingRate; } /** * Sets lossless. * * @param lossless whether the compression scheme is lossless. * @see #getLossless() */ public void setLossless(boolean lossless) { this.lossless = lossless; } /** * Gets lossless. * * @return whether the compression scheme is lossless. * @see #setLossless(boolean) */ public boolean getLossless() { return lossless; } /** * Sets filter. * * @param value which wavelet filters to use for the specified * tile-components. * @see #getFilter() */ public void setFilter(String value) { filter = value; } /** * Gets filters. * * @return which wavelet filters to use for the specified * tile-components. * @see #setFilter(String) */ public String getFilter() { return filter; } /** * Sets componentTransformation. * * @param value whether to utilize the component transformation. * @see #getComponentTransformation() */ public void setComponentTransformation(boolean value) { componentTransformation = value; } /** * Gets componentTransformation. * * @return whether to utilize the component transformation. * @see #setComponentTransformation(boolean) */ public boolean getComponentTransformation() { return componentTransformation; } /** * Sets codeBlockSize. * * @param value the maximum code-block size to use per tile-component. * @see #getCodeBlockSize() */ public void setCodeBlockSize(int[] value) { codeBlockSize = value; } /** * Gets codeBlockSize. * * @return the maximum code-block size to use per tile-component. * @see #setCodeBlockSize(int[]) */ public int[] getCodeBlockSize() { return codeBlockSize; } /** * Sets SOP. * * @param value whether start of packet (SOP) markers should be used. * @see #getSOP() */ public void setSOP(boolean value) { SOP = value; } /** * Gets SOP. * * @return whether start of packet (SOP) markers should be used. * @see #setSOP(boolean) */ public boolean getSOP() { return SOP; } /** * Sets EPH. * * @param value whether end of packet header (EPH) markers should be used. * @see #getEPH() */ public void setEPH(boolean value) { EPH = value; } /** * Gets EPH. * * @return whether end of packet header (EPH) markers should be used. * @see #setEPH(boolean) */ public boolean getEPH() { return EPH; } /** * Sets progressionType. * * @param value which type of progression should be used when generating * the codestream. * @see #getProgressionType() */ public void setProgressionType(String value) { progressionType = value; } /** * Gets progressionType. * * @return which type of progression should be used when generating * the codestream. * @see #setProgressionType(String) */ public String getProgressionType() { return progressionType; } /** Sets writeCodeStreamOnly. * * @param value Whether the jpeg2000 code stream only or the jp2 format * will be written into the output. * @see #getWriteCodeStreamOnly() */ public void setWriteCodeStreamOnly(boolean value) { writeCodeStreamOnly = value; } /** Gets writeCodeStreamOnly. * * @return whether the jpeg2000 code stream only or the jp2 format * will be written into the output. * @see #setWriteCodeStreamOnly(boolean) */ public boolean getWriteCodeStreamOnly() { return writeCodeStreamOnly; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy