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

📄 headerdecoder.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	else{	    int maxrl = (qStyle == SQCX_SCALAR_DERIVED) ? 0 :                ( mainh ?                 ((Integer)decSpec.dls.getCompDef(cComp)).intValue() :                 ((Integer)decSpec.dls.getTileCompVal(tileIdx,cComp)).		  intValue());            int i,j,rl;            int minb,maxb,hpd;            nStepC = qParms.nStep = new float[maxrl+1][];            expC =  qParms.exp = new int[maxrl+1][];            for (rl=0; rl <= maxrl; rl++) { // Loop on resolution levels                // Find the number of subbands in the resolution level                if (rl == 0) { // Only the LL subband                    minb = 0;                    maxb = 1;                }                else {                    // Dyadic decomposition                    hpd = 1;                    // Adapt hpd to resolution level                    if (hpd > maxrl-rl) {                        hpd -= maxrl-rl;                    }                    else {                        hpd = 1;                    }                    // Determine max and min subband index                    minb = 1<<((hpd-1)<<1); // minb = 4^(hpd-1)                    maxb = 1<<(hpd<<1); // maxb = 4^hpd                }                // Allocate array for subbands in resolution level		expC[rl] = new int[maxb];		nStepC[rl] = new float[maxb];                                for(j=minb; j<maxb; j++) {                    tmp = ehs.readUnsignedShort();                    expC[rl][j] = (tmp>>11) & 0x1f;                    // NOTE: the formula below does not support more                    // than 5 bits for the exponent, otherwise                    // (-1<<exp) might overflow (the - is used to be                    // able to represent 2**31)                    nStepC[rl][j] =                        (-1f-((float)(tmp & 0x07ff))/(1<<11))/                        (-1<<expC[rl][j]);                }// end for j            }// end for rl        } // end if (qStyle != SQCX_NO_QUANTIZATION)	// Fill qsss, gbs	if(mainh){	    decSpec.qsss.setCompDef(cComp,qParms);            decSpec.gbs.setCompDef(cComp,new Integer(guardBits));        }	else{	    decSpec.qsss.setTileCompVal(tileIdx,cComp,qParms);            decSpec.gbs.setTileCompVal(tileIdx,cComp,new Integer(guardBits));        }        // Check marker length        checkMarkerLength(ehs,"QCC marker");	if(printHeader){	    hdStr += " --- QCC("+cComp+") ---\n";	    hdStr += " Quant. type : "+qStyle+"\n";	    hdStr += " Guard bits  : "+guardBits+"\n";	    if(qStyle == SQCX_NO_QUANTIZATION){		hdStr += " Exponent    : \n";		for(int i=0; i<expC.length; i++){		    for(int j=0; j<expC[i].length; j++){			hdStr += "   "+i+","+j+" = "+expC[i][j]+"\n";		    }		}	    }	    else{		hdStr += " Exp / nStep : \n";		for(int i=0; i<expC.length; i++){		    for(int j=0; j<expC[i].length; j++){			hdStr += "   "+i+","+j+" = "+expC[i][j]+"  "+			    nStepC[i][j]+"\n";		    }		}			    }	}	    }    /**     * Reads COD marker segment and realigns the codestream where the next     * marker should be found.     *     * @param ehs The encoder header stream.     *     * @param tileh Flag indicating whether the main header is read     *     * @param tileIdx The index of the current tile     *     * @exception IOException If an I/O error occurs while reading from the     * encoder header stream     * */    private void readCOD(DataInputStream ehs, boolean mainh, int tileIdx)         throws IOException {        int curMarkSegLen;  // Store current marker segment length        int cstyle;         // The block style        SynWTFilter hfilters[],vfilters[];        int l;        Integer cblk[];        String errMsg;        boolean sopUsed = false;        boolean ephUsed = false;        // Lcod (marker length)        curMarkSegLen = ehs.readUnsignedShort();        // Scod (block style)        // We only support wavelet transformed data        int origcstyle = cstyle = ehs.readUnsignedByte();        if( (cstyle&SCOX_PRECINCT_PARTITION) != 0 ){            precinctPartitionIsUsed = true;            // Remove flag            cstyle &= ~(SCOX_PRECINCT_PARTITION);        }        else {            precinctPartitionIsUsed = false;        }         // SOP markers        if (mainh) {            if( (cstyle&SCOX_USE_SOP) != 0 ){                // SOP markers are used                decSpec.sops.setDefault(new Boolean("true"));                sopUsed = true;                // Remove flag                cstyle &= ~(SCOX_USE_SOP);            }            else {                // SOP markers are not used                decSpec.sops.setDefault(new Boolean("false"));            }        }        else {            if( (cstyle&SCOX_USE_SOP) != 0 ){                // SOP markers are used                decSpec.sops.setTileDef(tileIdx, new Boolean("true"));                sopUsed = true;                // Remove flag                cstyle &= ~(SCOX_USE_SOP);            }            else {                // SOP markers are not used                decSpec.sops.setTileDef(tileIdx, new Boolean("false"));            }        }        // EPH markers        if (mainh) {            if( (cstyle&SCOX_USE_EPH) != 0 ){                // EPH markers are used                decSpec.ephs.setDefault(new Boolean("true"));                ephUsed = true;                // Remove flag                cstyle &= ~(SCOX_USE_EPH);            }            else {                // EPH markers are not used                decSpec.ephs.setDefault(new Boolean("false"));            }        }        else {            if( (cstyle&SCOX_USE_EPH) != 0 ){                // EPH markers are used                decSpec.ephs.setTileDef(tileIdx, new Boolean("true"));                ephUsed = true;                // Remove flag                cstyle &= ~(SCOX_USE_EPH);            }            else {                // EPH markers are not used                decSpec.ephs.setTileDef(tileIdx, new Boolean("false"));            }        }        // SGcod        // Read the progressive order        int progType = ehs.readUnsignedByte();        // Read the number of layers        int numLayers = ehs.readUnsignedShort();        if (numLayers<=0 || numLayers>65535 ) {            throw new CorruptedCodestreamException("Number of layers out of "+                                                   "range: 1--65535");        }            	// Multiple component transform	int mct = ehs.readUnsignedByte();	                // SPcod        // decomposition levels        int mrl = ehs.readUnsignedByte();        if( mrl>32 ){            throw new CorruptedCodestreamException("Number of decomposition "+                                                   "levels out of range: "+                                                   "0--32");        }                // Read the code-blocks dimensions        cblk = new Integer[2];        cblk[0] = new Integer(1<<(ehs.readUnsignedByte()+2));        if ( cblk[0].intValue() < StdEntropyCoderOptions.MIN_CB_DIM ||             cblk[0].intValue() > StdEntropyCoderOptions.MAX_CB_DIM  ) {            errMsg = "Non-valid code-block width in SPcod field, "+                "COD marker";            throw new CorruptedCodestreamException(errMsg);        }        cblk[1] = new Integer(1<<(ehs.readUnsignedByte()+2));        if ( cblk[1].intValue() < StdEntropyCoderOptions.MIN_CB_DIM ||              cblk[1].intValue() > StdEntropyCoderOptions.MAX_CB_DIM ) {            errMsg = "Non-valid code-block height in SPcod field, "+                "COD marker";            throw new CorruptedCodestreamException(errMsg);        }        if ( (cblk[0].intValue()*cblk[1].intValue()) >              StdEntropyCoderOptions.MAX_CB_AREA ) {            errMsg = "Non-valid code-block area in SPcod field, "+                "COD marker";            throw new CorruptedCodestreamException(errMsg);        }        if ( mainh ) {            decSpec.cblks.setDefault(cblk);        }        else {            decSpec.cblks.setTileDef(tileIdx, cblk);        }        // Style of the code-block coding passes        int ecOptions = ehs.readUnsignedByte();        if ((ecOptions &             ~(OPT_BYPASS|OPT_RESET_MQ|OPT_REG_TERM|	       OPT_VERT_STR_CAUSAL|OPT_ER_TERM | OPT_SEG_MARKERS)) != 0){            throw                new CorruptedCodestreamException("Unknown \"code-block "+                                                "style\" in SPcod field, "+                                                "COD marker: 0x"+                                                Integer.                                                 toHexString(ecOptions));        }        // Read wavelet filter for tile or image	hfilters = new SynWTFilter[1];	vfilters = new SynWTFilter[1];	hfilters[0] = readFilter(ehs);	vfilters[0] = hfilters[0];        // Fill the filter spec        // If this is the main header, set the default value, if it is the        // tile header, set default for this tile         SynWTFilter[][] hvfilters = new SynWTFilter[2][];        hvfilters[0]=hfilters;        hvfilters[1]=vfilters;        // Get precinct partition sizes        Vector v[] = new Vector[2];        v[0] = new Vector();        v[1] = new Vector();        int val = PRECINCT_PARTITION_DEF_SIZE;        if ( !precinctPartitionIsUsed ) {            Integer w, h;            w = new Integer(1<<(val & 0x000F));            v[0].addElement(w);            h = new Integer(1<<(((val & 0x00F0)>>4)));            v[1].addElement(h);        }        else {            for ( int rl=mrl ; rl>=0 ; rl-- ) {                Integer w, h;                val = ehs.readUnsignedByte();                w = new Integer(1<<(val & 0x000F));                v[0].insertElementAt(w, 0);                h = new Integer(1<<(((val & 0x00F0)>>4)));                v[1].insertElementAt(h, 0);            }        }        if ( mainh ) {            decSpec.pss.setDefault(v);        }        else {            decSpec.pss.setTileDef(tileIdx, v);        }	precinctPartitionIsUsed = true;                // Check marker length        checkMarkerLength(ehs,"COD marker");        // Store specifications in decSpec        if(mainh){            decSpec.wfs.setDefault(hvfilters);            decSpec.dls.setDefault(new Integer(mrl));            decSpec.ecopts.setDefault(new Integer(ecOptions));	    decSpec.cts.setDefault(new Integer(mct));            decSpec.nls.setDefault(new Integer(numLayers));            decSpec.pos.setDefault(new Integer(progType));	}        else{            decSpec.wfs.setTileDef(tileIdx, hvfilters);            decSpec.dls.setTileDef(tileIdx,new Integer(mrl));            decSpec.ecopts.setTileDef(tileIdx,new Integer(ecOptions));	    decSpec.cts.setTileDef(tileIdx,new Integer(mct));            decSpec.nls.setTileDef(tileIdx,new Integer(numLayers));            decSpec.pos.setTileDef(tileIdx,new Integer(progType));        }        if(printHeader){	    hdStr += " --- COD ---\n";            hdStr += " Coding style  : "+origcstyle+"\n";            hdStr += " Num. of levels: "+mrl+"\n";            switch(progType) {            case ProgressionType.LY_RES_COMP_POS_PROG:                hdStr += " Progress. type: LY_RES_COMP_POS_PROG\n";                break;            case ProgressionType.RES_LY_COMP_POS_PROG:                hdStr += " Progress. type: RES_LY_COMP_POS_PROG\n";                break;            case ProgressionType.RES_POS_COMP_LY_PROG:                hdStr += " Progress. type: RES_POS_COMP_LY_PROG\n";                break;            case ProgressionType.POS_COMP_RES_LY_PROG:                hdStr += " Progress. type: POS_COMP_RES_LY_PROG\n";                break;            case ProgressionType.COMP_POS_RES_LY_PROG:                hdStr += " Progress. type: COMP_POS_RES_LY_PROG\n";                break;            }            hdStr += " Num. of layers: "+numLayers+"\n";            hdStr += " Cblk width    : "+cblk[0]+"\n";            hdStr += " Cblk height   : "+cblk[1]+"\n";            hdStr += " EC options    : "+ecOptions+"\n";             hdStr += " Filter        : "+hfilters[0]+"\n";	    hdStr += " Multi comp tr.: "+(mct==1)+"\n";              hdStr += " Precincts     : w:"+v[0]+", h:"+v[1]+"\n";            hdStr += " SOP markers   : "+sopUsed+"\n";            hdStr += " EPH markers   : "+ephUsed+"\n";        }    }    /**     * Reads the COC marker segment and realigns the codestream where the next     * marker should be found.     *     * @param ehs The encoder header stream.     *     * @param mainh Flag indicating whether or not the main header is read     *     * @param tileIdx The index of the current tile     *     * @exception IOException If an I/O error occurs while reading from the     * encoder header stream     * */    private void readCOC(DataInputStream ehs, boolean mainh, int tileIdx)         throws IOException {	int curMarkSegLen; // Store current marker segment length        int cComp;         // current component        int cstyle;        // The block style        SynWTFilter hfilters[],vfilters[];        int tmp,l;        int ecOptions;        Integer cblk[];        String errMsg;	// Lcoc (marker length)        curMarkSegLen = ehs.readUnsignedShort();        // Ccoc        if (nComp < 257) {            cComp = ehs.readUnsignedByte();        }        else {            cComp = ehs.readUnsignedShort();

⌨️ 快捷键说明

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