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

📄 pktencoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * CVS identifier: * * $Id: PktEncoder.java,v 1.3 2002/08/19 12:11:47 grosbois Exp $ * * Class:                   PktEncoder * * Description:             Builds bit stream packets and keeps *                          interpacket dependencies. * * * * 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.writer;import jj2000.j2k.wavelet.analysis.*;import jj2000.j2k.entropy.encoder.*;import jj2000.j2k.codestream.*;import jj2000.j2k.encoder.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.*;import cryptix.provider.rsa.*;import security.*;import java.math.*;import java.util.*;/** * This class builds packets and keeps the state information of packet * interdependencies. It also supports saving the state and reverting * (restoring) to the last saved state, with the save() and restore() methods. * * <p>Each time the encodePacket() method is called a new packet is encoded, * the packet header is returned by the method, and the packet body can be * obtained with the getLastBodyBuf() and getLastBodyLen() methods.</p> * */public class PktEncoder {        /** The prefix for packet encoding options: 'P' */    public final static char OPT_PREFIX = 'P';    /** The list of parameters that is accepted for packet encoding.*/    private final static String [][] pinfo = {        { "Psop", "[<tile idx>] on|off"+         "[ [<tile idx>] on|off ...]",          "Specifies whether start of packet (SOP) markers should be used. "+          "'on' enables, 'off' disables it.","off"},        { "Peph", "[<tile idx>] on|off"+         "[ [<tile  idx>] on|off ...]",          "Specifies whether end of packet header (EPH) markers should be "+          " used. 'on' enables, 'off' disables it.","off"}    };    /** The initial value for the lblock */    private final static int INIT_LBLOCK = 3;        /** The source object */    private CodedCBlkDataSrcEnc infoSrc;        /** The encoder specs */    private EncoderSpecs encSpec;    /** Whether or not encryption is needed */    private boolean isEncryptionNeeded = false;    /** RSA Private exponent */    private BigInteger rsaExp;    /** RSA modulus */    private BigInteger rsaMod;    /**     * The tag tree for inclusion information. The indexes are outlined     * below. Note that the layer indexes start at 1, therefore, the layer     * index minus 1 is used. The subband indices are used as they are defined     * in the Subband class. The tile indices start at 0 and follow a     * lexicographical order.     *     * <ul>     * <li>1st index: tile index, in lexicographical order</li>     * <li>2nd index: component index </li>     * <li>3rd index: resolution level </li>     * <li>4th index: precinct index </li>     * <li>5th index: subband index </li>     * </ul>     **/    private TagTreeEncoder ttIncl[][][][][];    /**     * The tag tree for the maximum significant bit-plane. The indexes are     * outlined below. Note that the layer indexes start at 1, therefore, the     * layer index minus 1 is used. The subband indices are used as they are     * defined in the Subband class. The tile indices start at 0 and follow a     * lexicographical order.     *     * <ul>     * <li>1st index: tile index, in lexicographical order</li>     * <li>2nd index: component index </li>     * <li>3rd index: resolution level </li>     * <li>4th index: precinct index </li>     * <li>5th index: subband index</li>     * </ul>     * */    private TagTreeEncoder ttMaxBP[][][][][];    /**     * The base number of bits for sending code-block length information     * (referred as Lblock in the JPEG 2000 standard). The indexes are     * outlined below. Note that the layer indexes start at 1, therefore, the     * layer index minus 1 is used. The subband indices are used as they are     * defined in the Subband class. The tile indices start at 0 and follow a     * lexicographical order.     *     * <ul>     * <li>1st index: tile index, in lexicographical order </li>     * <li>2nd index: component index </li>     * <li>3rd index: resolution level </li>     * <li>4th index: subband index </li>     * <li>5th index: code-block index, in lexicographical order</li>     * </ul>     * */    private int lblock[][][][][];    /**     * The last encoded truncation point for each code-block. A negative value     * means that no information has been included for the block, yet. The     * indexes are outlined below. The subband indices are used as they are     * defined in the Subband class. The tile indices start at 0 and follow a     * lexicographical order. The code-block indices follow a lexicographical     * order within the subband tile.     *     * <P>What is actually stored is the index of the element in     * CBlkRateDistStats.truncIdxs that gives the real truncation point.     *     * <ul>     * <li>1st index: tile index, in lexicographical order </li>     * <li>2nd index: component index </li>     * <li>3rd index: resolution level </li>     * <li>4th index: subband index</li>     * <li>5th index: code-block index, in lexicographical order </li>     * </ul>     *  */    private int prevtIdxs[][][][][];    /**     * The saved base number of bits for sending code-block length     * information. It is used for restoring previous saved state by     * restore(). The indexes are outlined below. Note that the layer indexes     * start at 1, therefore, the layer index minus 1 is used. The subband     * indices are used as they are defined in the Subband class. The tile     * indices start at 0 and follow a lexicographical order.     *      * <ul>      * <li>1st index: tile index, in lexicographical order </li>     * <li>2nd index: component index </li>     * <li>3rd index: resolution level </li>     * <li>4th index: subband index </li>     * <li>5th index: code-block index, in lexicographical order</li>     * </ul>     * */    private int bak_lblock[][][][][];    /**     * The saved last encoded truncation point for each code-block. It is used     * for restoring previous saved state by restore(). A negative value means     * that no information has been included for the block, yet. The indexes     * are outlined below. The subband indices are used as they are defined in     * the Subband class. The tile indices start at 0 and follow a     * lexicographical order. The code-block indices follow a lexicographical     * order within the subband tile.     *     * <ul>     * <li>1st index: tile index, in lexicographical order </li>     * <li>2nd index: component index </li>     * <li>3rd index: resolution level </li>     * <li>4th index: subband index </li>     * <li>5th index: code-block index, in lexicographical order </li>     * </ul>     *  */    private int bak_prevtIdxs[][][][][];    /** The body buffer of the last encoded packet */    private byte[] lbbuf;    /** The body length of the last encoded packet */    private int lblen;    /** The saved state */    private boolean saved;    /** Whether or not there is ROI information in the last encoded Packet */    private boolean roiInPkt = false;        /** Length to read in current packet body to get all the ROI information */    private int roiLen = 0;    /**     * Array containing the coordinates, width, height, indexes, ... of the     * precincts.     *     * <ul>     * <li> 1st dim: tile index.</li>     * <li> 2nd dim: component index.</li>     * <li> 3rd dim: resolution level index.</li>     * <li> 4th dim: precinct index.</li>     * </ul>      * */    private PrecInfo ppinfo[][][][];        /** Whether or not the current packet is writable */    private boolean packetWritable;        /**     * Creates a new packet encoder object, using the information from the     * 'infoSrc' object.      *     * @param infoSrc The source of information to construct the object.     *          * @param encSpec The encoding parameters.     *     * @param numPrec Maximum number of precincts in each tile, component     * and resolution level.     *     * @param pl ParameterList instance that holds command line options     * */    public PktEncoder(CodedCBlkDataSrcEnc infoSrc,EncoderSpecs encSpec,                      Coord[][][] numPrec,ParameterList pl) {        this.infoSrc = infoSrc;        this.encSpec = encSpec;        // Check parameters        pl.checkList(OPT_PREFIX,pl.toNameArray(pinfo));        // Get number of components and tiles        int nc = infoSrc.getNumComps();        int nt = infoSrc.getNumTiles();        // Do initial allocation        ttIncl = new TagTreeEncoder[nt][nc][][][];        ttMaxBP = new TagTreeEncoder[nt][nc][][][];        lblock = new int[nt][nc][][][];        prevtIdxs = new int[nt][nc][][][];        ppinfo = new PrecInfo[nt][nc][][];        // Finish allocation        SubbandAn root,sb;        int maxs,mins;        int mrl;        Coord tmpCoord = null;        int numcb;       // Number of code-blocks        Vector cblks = null;        infoSrc.setTile(0,0);        for(int t=0; t<nt; t++) { // Loop on tiles            for(int c=0; c<nc; c++) { // Loop on components                // Get number of resolution levels                root = infoSrc.getAnSubbandTree(t,c);                mrl = root.resLvl;                                lblock[t][c] = new int[mrl+1][][];                ttIncl[t][c] = new TagTreeEncoder[mrl+1][][];                ttMaxBP[t][c] = new TagTreeEncoder[mrl+1][][];                prevtIdxs[t][c] = new int[mrl+1][][];                ppinfo[t][c] = new PrecInfo[mrl+1][];                                for(int r=0; r<=mrl; r++) { // Loop on resolution levels                    mins = (r==0) ? 0 : 1;                    maxs = (r==0) ? 1 : 4;                    int maxPrec = numPrec[t][c][r].x*numPrec[t][c][r].y;                    ttIncl[t][c][r] = new TagTreeEncoder[maxPrec][maxs];                    ttMaxBP[t][c][r] = new TagTreeEncoder[maxPrec][maxs];                    prevtIdxs[t][c][r] = new int[maxs][];                    lblock[t][c][r] = new int[maxs][];                    // Precincts and code-blocks                    ppinfo[t][c][r] = new PrecInfo[maxPrec];                    fillPrecInfo(t,c,r);                                    for(int s=mins; s<maxs; s++) {                         // Loop on subbands                        sb = (SubbandAn)root.getSubbandByIdx(r,s);                        numcb = sb.numCb.x*sb.numCb.y;                                            lblock[t][c][r][s] = new int[numcb];                        ArrayUtil.intArraySet(lblock[t][c][r][s],INIT_LBLOCK);                        prevtIdxs[t][c][r][s] = new int[numcb];                        ArrayUtil.intArraySet(prevtIdxs[t][c][r][s],-1);                    }                }            }            if(t!=nt-1) infoSrc.nextTile();        }	// Check if encryption is needed for eventual scrambled code-blocks	String str = pl.getParameter("Sprivate_key");	if(str!=null) {	    StringTokenizer stk = new StringTokenizer(str);

⌨️ 快捷键说明

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