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

📄 headerencoder.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            hbuf.write(MathUtil.log2(tmp)-2);            tmp = encSpec.cblks.                getCBlkHeight(ModuleSpec.SPEC_DEF,-1,-1);            hbuf.write(MathUtil.log2(tmp)-2);        }        else {            // tile header, get tile default values            tmp = encSpec.cblks.                getCBlkWidth(ModuleSpec.SPEC_TILE_DEF,tileIdx,-1);            hbuf.write(MathUtil.log2(tmp)-2);            tmp = encSpec.cblks.                getCBlkHeight(ModuleSpec.SPEC_TILE_DEF,tileIdx,-1);            hbuf.write(MathUtil.log2(tmp)-2);        }	// Style of the code-block coding passes        tmp = 0;	if(mh){ // Main header	    // Selective arithmetic coding bypass ?	    if( ((String)encSpec.bms.getDefault()).equals("on")) {		tmp |= OPT_BYPASS;	    }	    // MQ reset after each coding pass ?	    if( ((String)encSpec.mqrs.getDefault()).equals("on")) {		tmp |= OPT_RESET_MQ;	    }	    // MQ termination after each arithmetically coded coding pass ?	    if(  ((String)encSpec.rts.getDefault()).equals("on") ) {		tmp |= OPT_REG_TERM;	    }	    // Vertically stripe-causal context mode ?	    if(  ((String)encSpec.css.getDefault()).equals("on") ) {		tmp |= OPT_VERT_STR_CAUSAL;	    }            // Predictable termination ?            if( ((String)encSpec.tts.getDefault()).equals("predict")){                tmp |= OPT_ER_TERM;            }	    // Error resilience segmentation symbol insertion ?	    if(  ((String)encSpec.sss.getDefault()).equals("on")) {		tmp |= OPT_SEG_MARKERS;	    }	}	else{ // Tile header	    // Selective arithmetic coding bypass ?	    if( ((String)encSpec.bms.getTileDef(tileIdx)).equals("on")) {		tmp |= OPT_BYPASS;	    }	    // MQ reset after each coding pass ?	    if( ((String)encSpec.mqrs.getTileDef(tileIdx)).equals("on")) {		tmp |= OPT_RESET_MQ;	    }	    // MQ termination after each arithmetically coded coding pass ?	    if(  ((String)encSpec.rts.getTileDef(tileIdx)).equals("on") ) {		tmp |= OPT_REG_TERM;	    }	    // Vertically stripe-causal context mode ?	    if(  ((String)encSpec.css.getTileDef(tileIdx)).equals("on") ) {		tmp |= OPT_VERT_STR_CAUSAL;	    }            // Predictable termination ?            if( ((String)encSpec.tts.getTileDef(tileIdx)).equals("predict")){                tmp |= OPT_ER_TERM;            }	    // Error resilience segmentation symbol insertion ?	    if(  ((String)encSpec.sss.getTileDef(tileIdx)).equals("on")) {		tmp |= OPT_SEG_MARKERS;	    }	}        hbuf.write(tmp);        // Wavelet transform        // Wavelet Filter	if(mh){	    filt=((AnWTFilter[][])encSpec.wfs.getDefault());	    hbuf.write(filt[0][0].getFilterType());	}else{	    filt=((AnWTFilter[][])encSpec.wfs.getTileDef(tileIdx));	    hbuf.write(filt[0][0].getFilterType());	}        // Precinct partition        if ( precinctPartitionUsed ) {            // Write the precinct size for each resolution level + 1            // (resolution 0) if precinct partition is used.            Vector v[] = null;            if ( mh ) {                v = (Vector[])encSpec.pss.getDefault();            }            else {                v = (Vector[])encSpec.pss.getTileDef(tileIdx);            }            for (int r=mrl ; r>=0 ; r--) {                if ( r>=v[1].size() ) {                    tmp = ((Integer)v[1].elementAt(v[1].size()-1)).                        intValue();                }                else {                    tmp = ((Integer)v[1].elementAt(r)).intValue();                }                int yExp = (MathUtil.log2(tmp)<< 4) & 0x00F0;                if ( r>=v[0].size() ) {                    tmp = ((Integer)v[0].elementAt(v[0].size()-1)).                        intValue();                }                else {                    tmp = ((Integer)v[0].elementAt(r)).intValue();                }                int xExp = MathUtil.log2(tmp) & 0x000F;                hbuf.write(yExp|xExp);            }        }    }    /**     * Writes COC marker segment . It is a functional marker containing the     * coding style for one component (coding style, decomposition, layering).     *     * <P>Its values overrides any value previously set in COD in the main     * header or in the tile header.     *     * @param mh Flag indicating whether the main header is to be written      *     * @param tileIdx Tile index     *      * @param compIdx index of the component which need use of the COC marker     * segment.     *     * @see #writeCOD     * */    protected void writeCOC(boolean mh, int tileIdx, int compIdx) 	throws IOException {	AnWTFilter[][] filt;        boolean precinctPartitionUsed;        int tmp;        int mrl=0,a=0;        int ppx=0, ppy=0;	Progression[] prog;                if (mh) {	    mrl = ((Integer)encSpec.dls.getCompDef(compIdx)).intValue();            // Get precinct size for specified component            ppx = encSpec.pss.getPPX(-1, compIdx, mrl);            ppy = encSpec.pss.getPPY(-1, compIdx, mrl);	    prog = (Progression[])(encSpec.ps.getCompDef(compIdx));        }        else {            mrl = ((Integer)encSpec.dls.getTileCompVal(tileIdx,compIdx)).		intValue();            // Get precinct size for specified component/tile            ppx = encSpec.pss.getPPX(tileIdx, compIdx, mrl);            ppy = encSpec.pss.getPPY(tileIdx, compIdx, mrl);	    prog = (Progression[])(encSpec.ps.getTileCompVal(tileIdx,compIdx));        }        if ( ppx != Markers.PRECINCT_PARTITION_DEF_SIZE ||             ppy != Markers.PRECINCT_PARTITION_DEF_SIZE ) {            precinctPartitionUsed = true;        }        else {            precinctPartitionUsed = false;        }        if ( precinctPartitionUsed ) {            // If precinct partition is used we add one byte per resolution 	    // level  i.e. mrl+1 (+1 for resolution 0).            a = mrl+1;        }                    // COC marker        hbuf.writeShort(COC);                // Lcoc (marker segment length (in bytes))        // Basic: Lcoc(2 bytes)+Scoc(1)+ Ccoc(1 or 2)+SPcod(5+a)        int markSegLen = 8 + ((nComp < 257) ? 1 : 2)+a;        // Rounded to the nearest even value greater or equals        hbuf.writeShort(markSegLen);                // Ccoc        if(nComp < 257) {            hbuf.write(compIdx);        }        else {            hbuf.writeShort(compIdx);        }        // Scod (coding style parameter)	tmp=0;        if ( precinctPartitionUsed ) {            tmp=SCOX_PRECINCT_PARTITION;        }	hbuf.write(tmp);        // SPcoc        // Number of decomposition levels        hbuf.write(mrl);                // Code-block width and height        if ( mh ) {            // main header, get component default values            tmp = encSpec.cblks.                getCBlkWidth(ModuleSpec.SPEC_COMP_DEF, -1, compIdx);            hbuf.write(MathUtil.log2(tmp)-2);            tmp = encSpec.cblks.                getCBlkHeight(ModuleSpec.SPEC_COMP_DEF, -1, compIdx);            hbuf.write(MathUtil.log2(tmp)-2);        }        else {            // tile header, get tile component values            tmp = encSpec.cblks.                getCBlkWidth(ModuleSpec.SPEC_TILE_COMP, tileIdx, compIdx);            hbuf.write(MathUtil.log2(tmp)-2);            tmp = encSpec.cblks.                getCBlkHeight(ModuleSpec.SPEC_TILE_COMP, tileIdx, compIdx);            hbuf.write(MathUtil.log2(tmp)-2);        }        // Entropy coding mode options        tmp = 0;	if(mh){ // Main header	    // Lazy coding mode ?	    if( ((String)encSpec.bms.getCompDef(compIdx)).equals("on")) {		tmp |= OPT_BYPASS;	    }	    // MQ reset after each coding pass ?	    if( ((String)encSpec.mqrs.getCompDef(compIdx)).		equalsIgnoreCase("on")) {		tmp |= OPT_RESET_MQ;	    }	    // MQ termination after each arithmetically coded coding pass ?	    if(  ((String)encSpec.rts.getCompDef(compIdx)).equals("on") ) {		tmp |= OPT_REG_TERM;	    }	    // Vertically stripe-causal context mode ?	    if(  ((String)encSpec.css.getCompDef(compIdx)).equals("on") ) {		tmp |= OPT_VERT_STR_CAUSAL;	    }            // Predictable termination ?            if( ((String)encSpec.tts.getCompDef(compIdx)).equals("predict")){                tmp |= OPT_ER_TERM;            }	    // Error resilience segmentation symbol insertion ?	    if(  ((String)encSpec.sss.getCompDef(compIdx)).equals("on")) {		tmp |= OPT_SEG_MARKERS;	    }	}	else{ // Tile Header	    if( ((String)encSpec.bms.getTileCompVal(tileIdx,compIdx)).		equals("on")) {		tmp |= OPT_BYPASS;	    }	    // MQ reset after each coding pass ?	    if( ((String)encSpec.mqrs.getTileCompVal(tileIdx,compIdx)).		equals("on")) {		tmp |= OPT_RESET_MQ;	    }	    // MQ termination after each arithmetically coded coding pass ?	    if(  ((String)encSpec.rts.getTileCompVal(tileIdx,compIdx)).		 equals("on") ) {		tmp |= OPT_REG_TERM;	    }	    // Vertically stripe-causal context mode ?	    if(  ((String)encSpec.css.getTileCompVal(tileIdx,compIdx)).		 equals("on") ) {		tmp |= OPT_VERT_STR_CAUSAL;	    }            // Predictable termination ?            if( ((String)encSpec.tts.getTileCompVal(tileIdx,compIdx)).                equals("predict")){                tmp |= OPT_ER_TERM;            }	    // Error resilience segmentation symbol insertion ?	    if(  ((String)encSpec.sss.getTileCompVal(tileIdx,compIdx)).		 equals("on")) {		tmp |= OPT_SEG_MARKERS;	    }	}	hbuf.write(tmp);        // Wavelet transform        // Wavelet Filter	if(mh){	    filt=((AnWTFilter[][])encSpec.wfs.getCompDef(compIdx));	    hbuf.write(filt[0][0].getFilterType());	}else{	    filt=((AnWTFilter[][])encSpec.wfs.getTileCompVal(tileIdx,compIdx));	    hbuf.write(filt[0][0].getFilterType());	}        // Precinct partition        if ( precinctPartitionUsed ) {            // Write the precinct size for each resolution level + 1            // (resolution 0) if precinct partition is used.            Vector v[] = null;            if ( mh ) {                v = (Vector[])encSpec.pss.getCompDef(compIdx);            }            else {                v = (Vector[])encSpec.pss.getTileCompVal(tileIdx, compIdx);            }            for (int r=mrl ; r>=0 ; r--) {                if ( r>=v[1].size() ) {                    tmp = ((Integer)v[1].elementAt(v[1].size()-1)).                        intValue();                }                else {                    tmp = ((Integer)v[1].elementAt(r)).intValue();                }                int yExp = (MathUtil.log2(tmp)<< 4) & 0x00F0;                if ( r>=v[0].size() ) {                    tmp = ((Integer)v[0].elementAt(v[0].size()-1)).                        intValue();                }                else {                    tmp = ((Integer)v[0].elementAt(r)).intValue();                }                int xExp = MathUtil.log2(tmp) & 0x000F;                hbuf.write(yExp|xExp);            }        }    }    /**     * Writes QCD marker segment in main header. QCD is a functional marker     * segment countaining the quantization default used for compressing all     * the components in an image. The values can be overriden for an     * individual component by a QCC marker in either the main or the tile     * header.     * */    protected void writeMainQCD() throws IOException{        int c;        int mrl;        int qstyle;        float step;                int[] tcIdx = encSpec.dls.getDefRep();        SubbandAn sb,csb,            sbRoot = dwt.getSubbandTree(tcIdx[0],tcIdx[1]);        defimgn = dwt.getNomRangeBits(tcIdx[1]);        String qType = (String)encSpec.qts.getDefault();        float baseStep = ((Float)encSpec.qsss.getDefault()).floatValue();        int gb = ((Integer)encSpec.gbs.getDefault()).intValue();        boolean isDerived   = qType.equals("derived");        boolean isReversible = qType.equals("reversible");        int nqcd; // Number of quantization step-size to transmit        // Get the quantization style        qstyle = (isReversible) ? SQCX_NO_QUANTIZATION :	    ((isDerived) ? SQCX_SCALAR_DERIVED : SQCX_SCALAR_EXPOUNDED);        // QCD marker        hbuf.writeShort(QCD);                mrl = ((Integer)encSpec.dls.getDefault()).intValue();        // Compute the number of steps to send        switch (qstyle) {        case SQCX_SCALAR_DERIVED:            nqcd = 1; // Just the LL value            break;        case SQCX_NO_QUANTIZATION:        case SQCX_SCALAR_EXPOUNDED:            // One value per subband            nqcd=0;                        sb=sbRoot;            // Get the subband at first resolution level            sb = (SubbandAn) sb.getSubbandByIdx(0,0);            // Count total number of subbands            for (int j=0; j<=mrl; j++) {                csb = sb;                while (csb != null) {                    nqcd++;                    csb = (SubbandAn) csb.nextSubband();                }                // Go up one resolution level                sb = (SubbandAn) sb.getNextResLevel();            }            break;        default:            throw new Error("Internal JJ2000 error");        }                // Lqcd (marker segment length (in bytes))        // Lqcd(2 bytes)+Sqcd(1)+ SPqcd (2*Nqcd)        int markSegLen = 3 + ((isReversible) ? nqcd : 2*nqcd);        // Rounded to the nearest even value greater or equals        hbuf.writeShort(markSegLen);        // Sqcd        hbuf.write(qstyle+(gb<<SQCX_GB_SHIFT));        // SPqcd        switch (qstyle) {        case SQCX_NO_QUANTIZATION:	    sb = sbRoot;	    sb = (SubbandAn)sb.getSubbandByIdx(0,0);	                // Output one exponent per subband            for (int j=0; j<=mrl; j++) {		csb = sb;                while(csb != null) {                    int tmp = (defimgn + csb.anGainExp);                    hbuf.write(tmp<<SQCX_EXP_SHIFT);		    		    csb = (SubbandAn)csb.nextSubband();		    // Go up one resolution level		}		sb = (SubbandAn)sb.getNextResLevel();	    }	    break;        case SQCX_SCALAR_DERIVED:	    sb = sbRoot;	    sb = (SubbandAn)sb.getSubbandByIdx(0,0);                            // Calculate subband step (normalized to unit            // dynamic range)            step = baseStep/(1<<sb.level);                            // Write exponent-mantissa, 16 bits            hbuf.writeShort(StdQuantizer.                            convertToExpMantissa(step));            break;        case SQCX_SCALAR_EXPOUNDED:	    sb = sbRoot;	    sb = (SubbandAn)sb.getSubbandByIdx(0,0);            // Output one step per subband            for (int j=0; j<=mrl; j++) {		csb = sb;                while(csb != null) {                    // Calculate subband step (normalized to unit                    // dynamic range)

⌨️ 快捷键说明

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