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

📄 pktdecoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/** * CVS identifier: * * $Id: PktDecoder.java,v 1.1.1.1 2002/07/22 09:26:46 grosbois Exp $ * * Class:                   PktDecoder * * Description:             Reads packets heads and keeps location of *                          code-blocks' codewords * * * * 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.wavelet.synthesis.*;import jj2000.j2k.codestream.*;import jj2000.j2k.entropy.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import java.util.*;import java.io.*;/**  * This class is used to read packet's head and body. All the members must be * re-initialized at the beginning of each tile thanks to the restart() * method. * */public class PktDecoder implements StdEntropyCoderOptions {        /** Reference to the codestream reader agent */    private BitstreamReaderAgent src;    /** Flag indicating whether packed packet header was used for this tile */    private boolean pph = false;    /** The packed packet header if it was used */    private ByteArrayInputStream pphbais;        /** Reference to decoder specifications */    private DecoderSpecs decSpec;        /** Reference to the HeaderDecoder */    private HeaderDecoder hd;        /** Initial value of the state variable associated with code-block     * length. */    private final int INIT_LBLOCK = 3;        /** The wrapper to read bits for the packet heads */    private PktHeaderBitReader bin;        /** Reference to the stream where to read from */    private RandomAccessIO ehs;        /**      * Maximum number of precincts :     *     * <ul>     * <li> 1st dim: component index.</li>     * <li> 2nd dim: resolution level index.</li>     * </ul>     * */    private Coord[][] numPrec;        /** Index of the current tile */    private int tIdx;        /**      * Array containing the coordinates, width, height, indexes, ... of the     * precincts in the current tile:     *      * <ul>     * <li> 1st dim: component index.</li>     * <li> 2nd dim: resolution level index.</li>     * <li> 3rd dim: precinct index.</li>     * </ul>     * */    private PrecInfo[][][] ppinfo;        /**      * Lblock value used to read code size information in each packet head:     *     * <ul>     * <li> 1st dim: component index.</li>     * <li> 2nd dim: resolution level index.</li>     * <li> 3rd dim: subband index.</li>     * <li> 4th/5th dim: code-block index (vert. and horiz.).</li>     * </ul>      * */    private int[][][][][] lblock;        /**      * Tag tree used to read inclusion informations in packet's head:     *     * <ul>        * <li> 1st dim: component index.</li>     * <li> 2nd dim: resolution level index.</li>     * <li> 3rd dim: precinct index.</li>      * <li> 4th dim: subband index.</li>     * */    private TagTreeDecoder[][][][] ttIncl;        /**      * Tag tree used to read bit-depth information in packet's head:     *      * <ul>     * <li> 1st dim: component index.</li>     * <li> 2nd dim: resolution level index.</li>     * <li> 3rd dim: precinct index.</li>     * <li> 4th dim: subband index.</li>     * </ul>     * */    private TagTreeDecoder[][][][] ttMaxBP;        /** Number of layers in t he current tile */    private int nl = 0;        /** The number of components */    private int nc;        /** Whether or not SOP marker segment are used */    private boolean sopUsed = false;    /** Whether or not EPH marker are used */    private boolean ephUsed = false;        /** Index of the current packet in the tile. Used with SOP marker segment     * */     private int pktIdx;    /** List of code-blocks found in last read packet head (one list     * per subband) */    private Vector[] cblks;    /** Number of codeblocks encountered. used for ncb quit condition*/    private int ncb;    /** Maximum number of codeblocks to read before ncb quit condition is     * reached */    private int maxCB;    /** Flag indicating whether ncb quit condition has been reached */    private boolean ncbQuit;    /** The tile in which the ncb quit condition was reached */    private int tQuit;    /** The component in which the ncb quit condition was reached */    private int cQuit;    /** The subband in which the ncb quit condition was reached */    private int sQuit;    /** The resolution in which the ncb quit condition was reached */    private int rQuit;    /** The x position of the last code block before ncb quit reached */    private int xQuit;    /** The y position of the last code block before ncb quit reached  */    private int yQuit;    /** True if truncation mode is used. False if it is parsing mode */    private boolean isTruncMode;    /**      * Creates an empty PktDecoder object associated with given decoder     * specifications and HeaderDecoder. This object must be initialized     * thanks to the restart method before being used.     *     * @param decSpec The decoder specifications.     *     * @param hd The HeaderDecoder instance.     *     * @param ehs The stream where to read data from.     *     * @param src The bit stream reader agent.     *     * @param isTruncMode Whether or not truncation mode is required.     *     * @param maxCB The maximum number of code-blocks to read before ncbquit     *     * */    public PktDecoder(DecoderSpecs decSpec,HeaderDecoder hd,                      RandomAccessIO ehs,BitstreamReaderAgent src,                      boolean isTruncMode, int maxCB) {        this.decSpec = decSpec;        this.hd = hd;        this.ehs = ehs;	this.isTruncMode = isTruncMode;        bin = new PktHeaderBitReader(ehs);        this.src = src;        ncb = 0;        ncbQuit = false;        this.maxCB = maxCB;    }            /**      * Re-initialize the PktDecoder instance at the beginning of a new tile.     *      * @param nc The number of components in this tile     *     * @param mdl The maximum number of decomposition level in each component     * of this tile     *     * @param nl The number of layers in  this tile     *     * @param cbI The code-blocks array     *     * @param pph Flag indicating whether packed packet headers was used     *     * @param pphbais Stream containing the packed packet headers     * */    public CBlkInfo[][][][][] restart(int nc,int[] mdl,int nl,                                      CBlkInfo[][][][][] cbI, boolean pph,                                       ByteArrayInputStream pphbais) {        this.nc = nc;        this.nl = nl;        this.tIdx = src.getTileIdx();        this.pph = pph;        this.pphbais = pphbais;                sopUsed = ((Boolean)decSpec.sops.getTileDef(tIdx)).booleanValue();        pktIdx = 0;        ephUsed = ((Boolean)decSpec.ephs.getTileDef(tIdx)).booleanValue();        cbI = new CBlkInfo[nc][][][][];        lblock = new int[nc][][][][];        ttIncl = new TagTreeDecoder[nc][][][];        ttMaxBP = new TagTreeDecoder[nc][][][];        numPrec = new Coord[nc][];        ppinfo = new PrecInfo[nc][][];                // Used to compute the maximum number of precincts for each resolution        // level        int tcx0, tcy0, tcx1, tcy1; // Current tile position in the domain of        // the image component        int trx0, try0, trx1, try1; // Current tile position in the reduced        // resolution image domain        int xrsiz, yrsiz; // Component sub-sampling factors        SubbandSyn root,sb;        int mins,maxs;        Coord nBlk = null;        int cb0x = src.getCbULX();        int cb0y = src.getCbULY();        for(int c=0; c<nc; c++) {            cbI[c] = new CBlkInfo[mdl[c]+1][][][];            lblock[c] = new int[mdl[c]+1][][][];            ttIncl[c] = new TagTreeDecoder[mdl[c]+1][][];            ttMaxBP[c] = new TagTreeDecoder[mdl[c]+1][][];            numPrec[c] = new Coord[mdl[c]+1];            ppinfo[c] = new PrecInfo[mdl[c]+1][];                        // Get the tile-component coordinates on the reference grid            tcx0 = src.getResULX(c,mdl[c]);            tcy0 = src.getResULY(c,mdl[c]);            tcx1 = tcx0 + src.getTileCompWidth(tIdx,c,mdl[c]);            tcy1 = tcy0 + src.getTileCompHeight(tIdx,c,mdl[c]);            for(int r=0; r<=mdl[c]; r++) {                // Tile's coordinates in the reduced resolution image domain                trx0 = (int)Math.ceil(tcx0/(double)(1<<(mdl[c]-r)));                try0 = (int)Math.ceil(tcy0/(double)(1<<(mdl[c]-r)));                trx1 = (int)Math.ceil(tcx1/(double)(1<<(mdl[c]-r)));                try1 = (int)Math.ceil(tcy1/(double)(1<<(mdl[c]-r)));                // Calculate the maximum number of precincts for each                // resolution level taking into account tile specific options.                double twoppx = (double)getPPX(tIdx,c,r);                double twoppy = (double)getPPY(tIdx,c,r);                numPrec[c][r] = new Coord();                if (trx1>trx0) {                    numPrec[c][r].x = (int)Math.ceil((trx1-cb0x)/twoppx)                        - (int)Math.floor((trx0-cb0x)/twoppx);                } else {                    numPrec[c][r].x = 0;                }                if (try1>try0) {                    numPrec[c][r].y = (int)Math.ceil((try1-cb0y)/twoppy)                        - (int)Math.floor((try0-cb0y)/twoppy);                } else {                    numPrec[c][r].y = 0;                }                 // First and last subbands indexes                mins = (r==0) ? 0 : 1;                maxs = (r==0) ? 1 : 4;                int maxPrec = numPrec[c][r].x * numPrec[c][r].y;                ttIncl[c][r] = new TagTreeDecoder[maxPrec][maxs+1];                ttMaxBP[c][r] = new TagTreeDecoder[maxPrec][maxs+1];                cbI[c][r] = new CBlkInfo[maxs+1][][];                lblock[c][r] = new int[maxs+1][][];                ppinfo[c][r] = new PrecInfo[maxPrec];                fillPrecInfo(c,r,mdl[c]);                                root = (SubbandSyn)src.getSynSubbandTree(tIdx,c);                for(int s=mins; s<maxs; s++){                    sb = (SubbandSyn)root.getSubbandByIdx(r,s);                    nBlk = sb.numCb;                    cbI[c][r][s] = new CBlkInfo[nBlk.y][nBlk.x];                    lblock[c][r][s] = new int[nBlk.y][nBlk.x];                    for(int i=nBlk.y-1;i>=0;i--) {                        ArrayUtil.intArraySet(lblock[c][r][s][i],INIT_LBLOCK);                    }                } // loop on subbands            } // End loop on resolution levels        } // End loop on components

⌨️ 快捷键说明

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