⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cblksizespec.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * CVS identifier: * * $Id: CBlkSizeSpec.java,v 1.11 2001/02/14 10:38:18 grosbois Exp $ * * Class:                   CBlkSizeSpec * * Description:             Specification of the code-blocks size * * * * COPYRIGHT: *  * This software module was originally developed by Rapha雔 Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askel鰂 (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, F閘ix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. *  * Copyright (c) 1999/2000 JJ2000 Partners. * */package jj2000.j2k.entropy;import jj2000.j2k.codestream.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.*;import java.util.*;/** * This class extends ModuleSpec class for code-blocks sizes holding purposes. *  * <P>It stores the size a of code-block.  * */public class CBlkSizeSpec extends ModuleSpec {    /** Name of the option */    private static final String optName = "Cblksiz";    /** The maximum code-block width */    private int maxCBlkWidth = 0;    /** The maximum code-block height */    private int maxCBlkHeight = 0;    /**     * Creates a new CBlkSizeSpec object for the specified number of tiles and     * components.     *     * @param nt The number of tiles     *     * @param nc The number of components     *     * @param type the type of the specification module i.e. tile specific,     * component specific or both.     * */    public CBlkSizeSpec(int nt, int nc, byte type) {        super(nt, nc, type);    }        /**     * Creates a new CBlkSizeSpec object for the specified number of tiles and     * components and the ParameterList instance.     *     * @param nt The number of tiles     *     * @param nc The number of components     *     * @param type the type of the specification module i.e. tile specific,     * component specific or both.     *     * @param imgsrc The image source (used to get the image size)     *     * @param pl The ParameterList instance     * */    public CBlkSizeSpec(int nt, int nc, byte type, ParameterList pl) {        super(nt, nc, type);        boolean firstVal = true;        String param = pl.getParameter(optName);        // Precinct partition is used : parse arguments        StringTokenizer stk = new StringTokenizer(param);        byte curSpecType = SPEC_DEF; // Specification type of the                                     // current parameter        boolean[] tileSpec = null; // Tiles concerned by the specification        boolean[] compSpec = null; // Components concerned by the specification        int i, xIdx, ci, ti;        String word = null; // current word        String errMsg = null;        while( stk.hasMoreTokens() ) {            word = stk.nextToken();                        switch(word.charAt(0)){                        case 't': // Tiles specification                tileSpec = parseIdx(word, nTiles);                if(curSpecType==SPEC_COMP_DEF) {                    curSpecType = SPEC_TILE_COMP;                }                else {                    curSpecType = SPEC_TILE_DEF;                }                break;                            case 'c': // Components specification                compSpec = parseIdx(word, nComp);                if(curSpecType==SPEC_TILE_DEF) {                    curSpecType = SPEC_TILE_COMP;                }                else {                    curSpecType = SPEC_COMP_DEF;                }                break;                        default:                if ( !Character.isDigit(word.charAt(0)) ) {                    errMsg = "Bad construction for parameter: "+word;                    throw new IllegalArgumentException(errMsg);                 }                Integer dim[] = new Integer[2];                // Get code-block's width                try {                     dim[0] = new Integer(word);                    // Check that width is not >                    // StdEntropyCoderOptions.MAX_CB_DIM                    if( dim[0].intValue()>StdEntropyCoderOptions.MAX_CB_DIM ){                        errMsg = "'"+optName+"' option : the code-block's "+                            "width cannot be greater than "+                            StdEntropyCoderOptions.MAX_CB_DIM;                        throw new IllegalArgumentException(errMsg);                    }                    // Check that width is not <                    // StdEntropyCoderOptions.MIN_CB_DIM                    if( dim[0].intValue()<StdEntropyCoderOptions.MIN_CB_DIM ){                        errMsg = "'"+optName+"' option : the code-block's "+                            "width cannot be less than "+                            StdEntropyCoderOptions.MIN_CB_DIM;                        throw new IllegalArgumentException(errMsg);                    }                    // Check that width is a power of 2                    if ( dim[0].intValue() !=                         (1<<MathUtil.log2(dim[0].intValue())) ) {                        errMsg = "'"+optName+"' option : the code-block's "+                            "width must be a power of 2";                        throw new IllegalArgumentException(errMsg);                    }                }                catch( NumberFormatException e) {                     errMsg = "'"+optName+"' option : the code-block's "+                         "width could not be parsed.";                    throw new IllegalArgumentException(errMsg);                }                // Get the next word in option                try {                    word = stk.nextToken();                }                catch (NoSuchElementException e) {                     errMsg = "'"+optName+"' option : could not parse the "+                        "code-block's height";                    throw new IllegalArgumentException(errMsg);                                    }                // Get the code-block's height                try {                     dim[1] = new Integer(word);                    // Check that height is not >                    // StdEntropyCoderOptions.MAX_CB_DIM                    if ( dim[1].intValue()>StdEntropyCoderOptions.MAX_CB_DIM ){                        errMsg = "'"+optName+"' option : the code-block's "+                            "height cannot be greater than "+                            StdEntropyCoderOptions.MAX_CB_DIM;                        throw new IllegalArgumentException(errMsg);                    }                    // Check that height is not <                    // StdEntropyCoderOptions.MIN_CB_DIM                    if ( dim[1].intValue()<StdEntropyCoderOptions.MIN_CB_DIM ){                        errMsg = "'"+optName+"' option : the code-block's "+                            "height cannot be less than "+                            StdEntropyCoderOptions.MIN_CB_DIM;                        throw new IllegalArgumentException(errMsg);                    }                    // Check that height is a power of 2                    if ( dim[1].intValue() !=                         (1<<MathUtil.log2(dim[1].intValue())) ) {                        errMsg = "'"+optName+"' option : the code-block's "+                            "height must be a power of 2";                        throw new IllegalArgumentException(errMsg);                    }                    // Check that the code-block 'area' (i.e. width*height) is                    // not greater than StdEntropyCoderOptions.MAX_CB_AREA                    if ( dim[0].intValue()*dim[1].intValue() >                          StdEntropyCoderOptions.MAX_CB_AREA )                        {                            errMsg = "'"+optName+"' option : The "+                                "code-block's area (i.e. width*height) "+                                "cannot be greater than "+                                StdEntropyCoderOptions.MAX_CB_AREA;                            throw new IllegalArgumentException(errMsg);                        }                }                catch( NumberFormatException e) {                    errMsg = "'"+optName+"' option : the code-block's height "+                        "could not be parsed.";                    throw new IllegalArgumentException(errMsg);                }                // Store the maximum dimensions if necessary                if ( dim[0].intValue() > maxCBlkWidth ) {                    maxCBlkWidth = dim[0].intValue();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -