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

📄 bitstreamreaderagent.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * CVS identifier: * * $Id: BitstreamReaderAgent.java,v 1.18 2001/02/16 09:28:00 grosbois Exp $ * * Class:                   BitstreamReaderAgent * * Description:             The generic interface for bit stream *                          transport agents. * * * * 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.codestream.reader;import jj2000.j2k.quantization.dequantizer.*;import jj2000.j2k.wavelet.synthesis.*;import jj2000.j2k.entropy.decoder.*;import jj2000.j2k.codestream.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import jj2000.j2k.*;import java.io.*;/** * This is the generic interface for bit stream reader agents. A bit stream * reader agent is an entity that allows reading from a bit stream and * requesting compressed code-blocks. It can be a simple file reader, or a * network connection, or anything else. * * <P>The bit stream reader agent allows to make request for compressed block * data in any order. The amount of data returned would normally depend on the * data available at the time of the request, be it from a file or from a * network connection. * * <P>The bit stream reader agent has the notion of a current tile, and * coordinates are relative to the current tile, where applicable. * * <P>Resolution level 0 is the lowest resolution level, i.e. the LL subband * alone. * */public abstract class BitstreamReaderAgent implements CodedCBlkDataSrcDec {    /** The decoder specifications */    protected DecoderSpecs decSpec;    /**      * Whether or not the components in the current tile uses a derived     * quantization step size (only relevant in non reversible quantization     * mode). This field is actualized by the setTile method in     * FileBitstreamReaderAgent.     *     * @see FileBitstreamReaderAgent#initSubbandsFields      * */    protected boolean derived[] = null;    /**      * Number of guard bits off all component in the current tile. This field     * is actualized by the setTile method in FileBitstreamReaderAgent.     *     * @see FileBitstreamReaderAgent#initSubbandsFields     * */    protected int[] gb = null;    /**      * Dequantization parameters of all subbands and all components in the     * current tile. The value is actualized by the setTile method in     * FileBitstreamReaderAgent.     *     * @see FileBitstreamReaderAgent#initSubbandsFields     * */    protected StdDequantizerParams params[] = null;        /** The prefix for bit stream reader options: 'B' */    public final static char OPT_PREFIX = 'B';    /** The list of parameters that is accepted by the bit stream     * readers. They start with 'B'. */    private static final String [][] pinfo = null;    /**      * The maximum number of decompostion levels for each component of the     * current tile. It means that component c has mdl[c]+1 resolution levels     * (indexed from 0 to mdl[c])     * */    protected int mdl[];    /** The number of components */    protected final int nc;    /** Image resolution level to generate */    protected int res;    /**     * The subband trees for each component in the current tile. Each element     * in the array is the root element of the subband tree for a     * component. The number of magnitude bits in each subband (magBits member     * variable) is not initialized.     * */    protected SubbandSyn subbTrees[];    /** The image width on the hi-res reference grid */    protected final int imgW;    /** The image width on the hi-res reference grid */    protected final int imgH;    /** The horizontal coordinate of the image origin in the canvas system, on     * the reference grid. */    protected final int ax;    /** The vertical coordinate of the image origin in the canvas system, on     * the reference grid. */    protected final int ay;    /** The horizontal coordinate of the tiling origin in the canvas system, on     * the reference grid. */    protected final int px;    /** The vertical coordinate of the tiling origin in the canvas system, on     * the reference grid. */    protected final int py;    /** The horizontal offsets of the upper-left corner of the current tile     * (not active tile) with respect to the canvas origin, in the component     * hi-res grid, for each component. */    protected final int offX[];    /** The vertical offsets of the upper-left corner of the current tile (not     * active tile) with respect to the canvas origin, in the component hi-res     * grid, for each component. */    protected final int offY[];    /** The horizontal coordinates of the upper-left corner of the active     * tile, with respect to the canvas origin, in the component hi-res grid,     * for each component. */    protected final int culx[];    /** The vertical coordinates of the upper-left corner of the active tile,     * with respect to the canvas origin, in the component hi-res grid, for     * each component. */    protected final int culy[];    /** The nominal tile width, in the hi-res reference grid */    protected final int ntW;    /** The nominal tile height, in the hi-res reference grid */    protected final int ntH;    /** The number of tile in the horizontal direction */    protected final int ntX;    /** The number of tiles in the vertical direction */    protected final int ntY;    /** The current tile horizontal index */    protected int ctX;    /** The current tile vertical index */    protected int ctY;    /** The decoded bit stream header */    protected final HeaderDecoder hd;        /** Number of bytes targeted to be read */    protected int tnbytes;    /** Actual number of read bytes */    protected int anbytes;    /** Target decoding rate in bpp */    protected float trate;    /** Actual decoding rate in bpp */    protected float arate;    /**     * Initializes members of this class. This constructor takes a     * HeaderDecoder object. This object must be initialized by the     * constructor of the implementing class from the header of the bit     * stream.     *     * @param hd The decoded header of the bit stream from where to initialize     * the values.     *     * @param decSpec The decoder specifications     * */    protected BitstreamReaderAgent(HeaderDecoder hd,DecoderSpecs decSpec){        Coord co;        int i,j,max;        this.decSpec = decSpec;        this.hd = hd;        // Number of components        nc = hd.getNumComps();        offX = new int[nc];        offY = new int[nc];        culx = new int[nc];        culy = new int[nc];                // Image size and origin        imgW = hd.getImgWidth();        imgH = hd.getImgHeight();        ax = hd.getImgULX();        ay = hd.getImgULY();                // Tiles        co = hd.getTilingOrigin(null);        px = co.x;        py = co.y;        ntW = hd.getNomTileWidth();        ntH = hd.getNomTileHeight();        ntX = (ax+imgW-px+ntW-1) / ntW;        ntY = (ay+imgH-py+ntH-1) / ntH;    }    /**     * 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 final int getPartitionULX() {        return hd.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 hd.getPartitionULY();    }    /**     * Returns the number of components in the image.     *     * @return The number of components in the image.     * */    public final int getNumComps() {        return nc;    }    /**     * Returns the component subsampling factor in the horizontal direction,     * for the specified component. This is, approximately, the ratio of     * dimensions between the reference grid and the component itself, see the     * 'ImgData' interface desription for details.     *     * @param c The index of the component (between 0 and N-1)     *     * @return The horizontal subsampling factor of component 'c'     *     * @see ImgData     * */    public final int getCompSubsX(int c) {        return hd.getCompSubsX(c);    }    /**     * Returns the component subsampling factor in the vertical direction, for     * the specified component. This is, approximately, the ratio of     * dimensions between the reference grid and the component itself, see the     * 'ImgData' interface desription for details.     *     * @param c The index of the component (between 0 and C-1)     *     * @return The vertical subsampling factor of component 'c'     *     * @see ImgData     * */    public int getCompSubsY(int c) {        return hd.getCompSubsY(c);    }    /**     * Returns the overall width of the current tile in pixels for the given     * (tile) resolution level. This is the tile's width without accounting     * for any component subsampling.     *     * <P>Note: Tile resolution level indexes may be different from     * tile-component resolution index. They are indeed indexed starting from     * the lowest number of decomposition levels of each component of the     * tile.     *     * <P>For an image (1 tile) with 2 components (component 0 having 2     * decomposition levels and component 1 having 3 decomposition levels),     * the first (tile-)component has 3 resolution levels and the second one     * has 4 resolution levels, whereas the tile has only 3 resolution levels     * available.     *     * @param rl The (tile) resolution level.     *     * @return The current tile's width in pixels.     * */    public int getWidth(int rl){	// The minumum number of decomposition levels between all the	// components	int mindl = decSpec.dls.getMinInTile(getTileIdx());        if(rl>mindl){            throw new IllegalArgumentException("Requested resolution level"+                                               " is not available for, at "+                                               "least, one component in "+					       "tile: "+ctX+"x"+ctY);        }        int ctulx,ntulx;        int dl = mindl-rl; // Number of decomposition to obtain this	// resolution        // Calculate starting X of current tile at hi-res        ctulx = (ctX == 0) ? ax : px+ctX*ntW;        // Calculate starting X of next tile X-wise at hi-res        ntulx = (ctX < ntX-1) ? px+(ctX+1)*ntW : ax+imgW;        // The difference at the rl resolution level is the width        return (ntulx+(1<<dl)-1)/(1<<dl)-(ctulx+(1<<dl)-1)/(1<<dl);    }    /**     * Returns the overall height of the current tile in pixels, for the given     * resolution level. This is the tile's height without accounting for any     * component subsampling.     *     * <P>Note: Tile resolution level indexes may be different from     * tile-component resolution index. They are indeed indexed starting from     * the lowest number of decomposition levels of each component of the     * tile.     *     * <P>For an image (1 tile) with 2 components (component 0 having 2     * decomposition levels and component 1 having 3 decomposition levels),     * the first (tile-)component has 3 resolution levels and the second one     * has 4 resolution levels, whereas the tile has only 3 resolution levels     * available.     *     * @param rl The (tile) resolution level.     *     * @return The total current tile's height in pixels.     * */    public int getHeight(int rl){	// The minumum number of decomposition levels between all the	// components	int mindl = decSpec.dls.getMinInTile(getTileIdx());        if(rl>mindl){            throw new IllegalArgumentException("Requested resolution level"+                                               " is not available for, at "+

⌨️ 快捷键说明

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