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

📄 roidescaler.java

📁 jpeg2000算法实现
💻 JAVA
字号:
/* * CVS identifier: * * $Id: ROIDeScaler.java,v 1.35 2001/03/01 09:37:14 grosbois Exp $ * * * Class:                   ROIDeScaler * * Description:             The class taking care of de-scaling ROI coeffs. * * * * 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.roi;import jj2000.j2k.quantization.dequantizer.*;import jj2000.j2k.codestream.reader.*;import jj2000.j2k.wavelet.synthesis.*;import jj2000.j2k.codestream.*;import jj2000.j2k.entropy.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import jj2000.j2k.*;import java.io.*;/** * This class takes care of the de-scaling of ROI coefficients. The de-scaler * works on a tile basis and any mask that is generated is for the current * mask only * * <P>Default implementations of the methods in 'MultiResImgData' are provided * through the 'MultiResImgDataAdapter' abstract class. * * <P>Sign magnitude representation is used (instead of two's complement) for * the output data. The most significant bit is used for the sign (0 if * positive, 1 if negative). Then the magnitude of the quantized coefficient * is stored in the next most significat bits. The most significant magnitude * bit corresponds to the most significant bit-plane and so on. * */public class ROIDeScaler extends MultiResImgDataAdapter    implements CBlkQuantDataSrcDec{    /** The MaxShiftSpec containing the scaling values for all tile-components     * */    private MaxShiftSpec mss;    /** The prefix for ROI decoder options: 'R' */    public final static char OPT_PREFIX = 'R';    /** The list of parameters that is accepted by the entropy decoders. They     * start with 'R'. */    private final static String [][] pinfo = {	{ "Rno_roi",null,	  "This argument makes sure that the no ROI de-scaling is performed. "+	  "Decompression is done like there is no ROI in the image",null},    };    /** The entropy decoder from where to get the compressed data (the source)     * */    private CBlkQuantDataSrcDec src;    /**     * Constructor of the ROI descaler, takes EntropyDEcoder as source of data     * to de-scale.     *     * @param src The EntropyDecoder that is the source of data.     *     * @param mss The MaxShiftSpec containing the scaling values for all     * tile-components     * */    public ROIDeScaler(CBlkQuantDataSrcDec src, MaxShiftSpec mss){        super(src);        this.src=src;        this.mss=mss;    }    /**     * Returns the subband tree, for the specified tile-component. This method     * returns the root element of the subband tree structure, see Subband and     * SubbandSyn. The tree comprises all the available resolution levels.     *     * <P>The number of magnitude bits ('magBits' member variable) for each     * subband is not initialized.     *     * @param t The index of the tile, from 0 to T-1.     *     * @param c The index of the component, from 0 to C-1.     *     * @return The root of the tree structure.     * */    public SubbandSyn getSubbandTree(int t,int c) {        return src.getSubbandTree(t,c);    }    /**     * Returns the horizontal coordinate of the origin of the cell and     * code-block partition, with respect to the canvas origin, on the     * reference grid. Allowable values are 0 and 1, nothing else.     *     * @return The horizontal coordinate of the origin of the cell and     * code-block partitions, with respect to the canvas origin, on the     * reference grid.     * */    public int getPartitionULX() {        return src.getPartitionULX();    }    /**     * Returns the vertical coordinate of the origin of the cell and     * code-block partition, with respect to the canvas origin, on the     * reference grid. Allowable values are 0 and 1, nothing else.     *     * @return The vertical coordinate of the origin of the cell and     * code-block partitions, with respect to the canvas origin, on the     * reference grid.     * */    public int getPartitionULY() {        return src.getPartitionULY();    }    /**     * Returns the parameters that are used in this class and implementing     * classes. It returns a 2D String array. Each of the 1D arrays is for a     * different option, and they have 3 elements. The first element is the     * option name, the second one is the synopsis and the third one is a long     * description of what the parameter is. The synopsis or description may     * be 'null', in which case it is assumed that there is no synopsis or     * description of the option, respectively. Null may be returned if no     * options are supported.     *     * @return the options name, their synopsis and their explanation, or null     * if no options are supported.     * */    public static String[][] getParameterInfo() {        return pinfo;    }    /**     * Returns the number of code-blocks in a subband, along the horizontal     * and vertical dimensions.     *     * @param sb The subband for which to return the number of blocks.     *     * @param n The component where the subband is.     *     * @param co If not null the values are returned in this object. If null a     * new object is allocated and returned.     *     * @return The number of code-blocks along the horizontal dimension in     * 'Coord.x' and the number of code-blocks along the vertical dimension in     * 'Coord.y'.     * */    public Coord getNumCodeBlocks(SubbandSyn sb, int n, Coord co){        return src.getNumCodeBlocks(sb,n,co);    }    /**     * Returns the specified code-block in the current tile for the specified     * component, as a copy (see below).     *     * <P>The returned code-block may be progressive, which is indicated by     * the 'progressive' variable of the returned 'DataBlk' object. If a     * code-block is progressive it means that in a later request to this     * method for the same code-block it is possible to retrieve data which is     * a better approximation, since meanwhile more data to decode for the     * code-block could have been received. If the code-block is not     * progressive then later calls to this method for the same code-block     * will return the exact same data values.     *     * <P>The data returned by this method is always a copy of the internal     * data of this object, if any, and it can be modified "in place" without     * any problems after being returned. The 'offset' of the returned data is     * 0, and the 'scanw' is the same as the code-block width. See the     * 'DataBlk' class.     *     * <P>The 'ulx' and 'uly' members of the returned 'DataBlk' object contain     * the coordinates of the top-left corner of the block, with respect to     * the tile, not the subband.     *     * @param c The component for which to return the next code-block.     *     * @param m The vertical index of the code-block to return, in the     * specified subband.     *     * @param n The horizontal index of the code-block to return, in the     * specified subband.     *     * @param sb The subband in which the code-block to return is.     *     * @param cblk If non-null this object will be used to return the new     * code-block. If null a new one will be allocated and returned. If the     * "data" array of the object is non-null it will be reused, if possible,     * to return the data.     *     * @return The next code-block in the current tile for component 'n', or     * null if all code-blocks for the current tile have been returned.     *     * @see DataBlk     * */    public DataBlk getCodeBlock(int c, int m, int n, SubbandSyn sb,                                  DataBlk cblk){        return getInternCodeBlock(c,m,n,sb,cblk);    }        /**     * Returns the specified code-block in the current tile for the specified     * component (as a reference or copy).     *     * <P>The returned code-block may be progressive, which is indicated by     * the 'progressive' variable of the returned 'DataBlk' object. If a     * code-block is progressive it means that in a later request to this     * method for the same code-block it is possible to retrieve data which is     * a better approximation, since meanwhile more data to decode for the     * code-block could have been received. If the code-block is not     * progressive then later calls to this method for the same code-block     * will return the exact same data values.     *     * <P>The data returned by this method can be the data in the internal     * buffer of this object, if any, and thus can not be modified by the     * caller. The 'offset' and 'scanw' of the returned data can be     * arbitrary. See the 'DataBlk' class.     *     * <P>The 'ulx' and 'uly' members of the returned 'DataBlk' object contain     * the coordinates of the top-left corner of the block, with respect to     * the tile, not the subband.     *     * @param c The component for which to return the next code-block.     *     * @param m The vertical index of the code-block to return, in the     * specified subband.     *     * @param n The horizontal index of the code-block to return, in the     * specified subband.     *     * @param sb The subband in which the code-block to return is.     *     * @param cblk If non-null this object will be used to return the new     * code-block. If null a new one will be allocated and returned. If the     * "data" array of the object is non-null it will be reused, if possible,     * to return the data.     *     * @return The requested code-block in the current tile for component 'c'.     *     * @see DataBlk     * */    public DataBlk getInternCodeBlock(int c, int m, int n, SubbandSyn sb,                                        DataBlk cblk){        int mi,i,j,k,wrap;        int ulx, uly, w, h;        int[] data;                       // local copy of quantized data        int tmp;        int limit;        // Get data block from entropy decoder        cblk = src.getInternCodeBlock(c,m,n,sb,cblk);        // If there are no ROIs in the tile, Or if we already got all blocks        boolean noRoiInTile = false;        if(mss==null || mss.getTileCompVal(getTileIdx(),c)==null )            noRoiInTile = true;        if (noRoiInTile || cblk==null) {             return cblk;        }        data = (int[])cblk.getData();        ulx = cblk.ulx;        uly = cblk.uly;        w = cblk.w;        h = cblk.h;	// Scale coefficients according to magnitude. If the magnitude of a	// coefficient is lower than 2 pow 31-magbits then it is a background	// coeff and should be up-scaled	int boost = ((Integer) mss.getTileCompVal(getTileIdx(),c)).intValue();        int mask = ((1<<sb.magbits)-1)<<(31-sb.magbits);        int mask2 = (~mask)&0x7FFFFFFF;	wrap=cblk.scanw-w;	i=cblk.offset+cblk.scanw*(h-1)+w-1;	for(j=h;j>0;j--){	    for(k=w;k>0;k--,i--){		tmp=data[i];		if((tmp & mask) == 0 ) { // BG		    data[i] = (tmp & 0x80000000) | (tmp << boost);		}                else { // ROI                    if ((tmp & mask2) != 0) {                        // decoded more than magbits bit-planes, set                        // quantization mid-interval approx. bit just after                        // the magbits.                        data[i] = (tmp&(~mask2)) | (1<<(30-sb.magbits));                    }                }	    }	    i-=wrap;	}        return cblk;        }        /**     * Creates a ROIDeScaler object. The information needed to create the     * object is the Entropy decoder used and the parameters.     *     * @param src The source of data that is to be descaled     *     * @param pl The parameter list (or options).     *     * @param decSpec The decoding specifications     *     * @exception IllegalArgumentException If an error occurs while parsing     * the options in 'pl'     * */    public static ROIDeScaler createInstance(CBlkQuantDataSrcDec src,                                             ParameterList pl,                                             DecoderSpecs decSpec){        String noRoi;        int i;        // Check parameters        pl.checkList(OPT_PREFIX,pl.toNameArray(pinfo));        // Check if no_roi specified in command line or no roi signalled	// in bit stream        noRoi = pl.getParameter("Rno_roi");        if (noRoi != null || decSpec.rois == null) {            // no_roi specified in commandline!	    return new ROIDeScaler(src,null);        }        return new ROIDeScaler( src, decSpec.rois );    }}

⌨️ 快捷键说明

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