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

📄 headerdecoder.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // Check marker length        checkMarkerLength(ehs,"CRG marker");    }        /**     * Reads COM marker segments and realign the bistream at the point where     * the next marker should be found.     *     * @param ehs The encoded header stream     *     * @exception IOException If an I/O error occurs while reading from the     * encoded header stream     * */    private void readCOM(DataInputStream ehs) throws IOException{        int curMarkSegLen;  // Store the length of current segment        	// Read length of COM field	curMarkSegLen = ehs.readUnsignedShort();        	// Read the registration value of the COM marker segment        int rcom = ehs.readUnsignedShort();	switch(rcom) {        case RCOM_GEN_USE:            byte[] b = new byte[curMarkSegLen-4];            for(int i=0; i<b.length; i++) {                b[i] = ehs.readByte();            }            if(pl.getBooleanParameter("verbose")) {                FacilityManager.getMsgLogger().println(new String(b),8,2);            }            break;	default:            // --- Unknown and unsupported markers ---            // (skip them and see if we can get way with it)            FacilityManager.getMsgLogger().                printmsg(MsgLogger.WARNING,                         "COM marker registered as 0x"+Integer.                         toHexString(rcom)+                         " unknown, ignoring (this might crash the "+                         "decoder or decode a quality degraded or even "+                         "useless image)");            ehs.skipBytes(curMarkSegLen-4); //Ignore this field for the moment	    break;	}                // Check marker length        checkMarkerLength(ehs,"COM marker");    }    /**     * Reads QCD marker segment and realigns the codestream at the point where     * the next marker should be found.     *      * @param ehs The encoded 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     * encoded header stream.     * */    private void readQCD(DataInputStream ehs, boolean mainh, int tileIdx)         throws IOException {        int curMarkSegLen;  // Store the length of current field	StdDequantizerParams qParms;        int guardBits;	int[][] exp;	float[][] nStep = null;		// Lqcd (length of QCD field)	curMarkSegLen = ehs.readUnsignedShort();		// Sqcd (quantization style)        int qStyle = ehs.readUnsignedByte();		guardBits = (qStyle>>SQCX_GB_SHIFT)&SQCX_GB_MSK;	qStyle &= ~(SQCX_GB_MSK<<SQCX_GB_SHIFT);        if(mainh){            // If the main header is being read set default value of            // dequantization spec            switch (qStyle) {            case SQCX_NO_QUANTIZATION:                decSpec.qts.setDefault("reversible");                break;            case SQCX_SCALAR_DERIVED:                decSpec.qts.setDefault("derived");                break;            case SQCX_SCALAR_EXPOUNDED:                decSpec.qts.setDefault("expounded");                break;            default:                throw new CorruptedCodestreamException("Unknown or "+                                                       "unsupported "+                                                      "quantization style "+                                                      "in Sqcd field, QCD "+                                                      "marker main header");            }        } else {            // If the tile header is being read set default value of            // dequantization spec for tile            switch (qStyle) {            case SQCX_NO_QUANTIZATION:                decSpec.qts.setTileDef(tileIdx, "reversible");                break;            case SQCX_SCALAR_DERIVED:                decSpec.qts.setTileDef(tileIdx, "derived");                break;            case SQCX_SCALAR_EXPOUNDED:                decSpec.qts.setTileDef(tileIdx, "expounded");                break;            default:                throw new CorruptedCodestreamException("Unknown or "+                                                       "unsupported "+                                                      "quantization style "+                                                      "in Sqcd field, QCD "+                                                      "marker, tile header");            }        }        qParms = new StdDequantizerParams();        if(qStyle == SQCX_NO_QUANTIZATION) {	    int maxrl = (qStyle == SQCX_SCALAR_DERIVED) ? 0 :                ( mainh ?                 ((Integer)decSpec.dls.getDefault()).intValue() :                 ((Integer)decSpec.dls.getTileDef(tileIdx)).intValue());            int i,j,rl;            int minb,maxb,hpd;            int tmp;	    exp = 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		exp[rl] = new int[maxb];                for(j=minb; j<maxb; j++) {                    tmp = ehs.readUnsignedByte();		    exp[rl][j] = (tmp>>SQCX_EXP_SHIFT)&SQCX_EXP_MASK;                }// end for j            }// end for rl	}	else{	    int maxrl = (qStyle == SQCX_SCALAR_DERIVED) ? 0 :                ( mainh ?                 ((Integer)decSpec.dls.getDefault()).intValue() :                 ((Integer)decSpec.dls.getTileDef(tileIdx)).intValue());            int i,j,rl;            int minb,maxb,hpd;            int tmp;            exp = qParms.exp = new int[maxrl+1][];            nStep = qParms.nStep = new float[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		exp[rl] = new int[maxb];		nStep[rl] = new float[maxb];                for(j=minb; j<maxb; j++) {                    tmp = ehs.readUnsignedShort();		    exp[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)		    nStep[rl][j] =			(-1f-((float)(tmp & 0x07ff))/(1<<11))/			(-1<<exp[rl][j]);                }// end for j            }// end for rl        } // end if (qStyle != SQCX_NO_QUANTIZATION)	// Fill qsss, gbs	if(mainh){	    decSpec.qsss.setDefault(qParms);            decSpec.gbs.setDefault(new Integer(guardBits));        }	else{	    decSpec.qsss.setTileDef(tileIdx,qParms);            decSpec.gbs.setTileDef(tileIdx,new Integer(guardBits));        }        // Check marker length        checkMarkerLength(ehs,"QCD marker");	if(printHeader){	    hdStr += " --- QCD ---\n";	    hdStr += " Quant. type : "+qStyle+"\n";	    hdStr += " Guard bits  : "+guardBits+"\n";	    if(qStyle == SQCX_NO_QUANTIZATION){		hdStr += " Exponent    : \n";		for(int i=0; i<exp.length; i++){		    for(int j=0; j<exp[i].length; j++){			hdStr += "   "+i+","+j+" = "+exp[i][j]+"\n";		    }		}	    }	    else{		hdStr += " Exp / nStep : \n";		for(int i=0; i<exp.length; i++){		    for(int j=0; j<exp[i].length; j++){			hdStr += "   "+i+","+j+" = "+exp[i][j]+"  "+			    nStep[i][j]+"\n";		    }		}			    }	}    }    /**     * Reads QCC marker segment and realigns the codestream at the point where     * the next marker should be found.     *      * @param ehs The encoded 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     * encoded header stream.     * */    private void readQCC(DataInputStream ehs, boolean mainh, int tileIdx)        throws IOException {        int curMarkSegLen;  // Store the length of current field        int cComp;          // current component        int tmp;	StdDequantizerParams qParms;        int guardBits;	int[][] expC;	float[][] nStepC = null;	// Lqcc (length of QCC field)	curMarkSegLen = ehs.readUnsignedShort();	        // Cqcc        if (nComp < 257) {            cComp = ehs.readUnsignedByte();        }        else {            cComp = ehs.readUnsignedShort();        }        if (cComp >= nComp) {            throw new CorruptedCodestreamException("Invalid component "+                                                   "index in QCC marker");        }		// Sqcc (quantization style)	tmp = ehs.readUnsignedByte();	guardBits =((tmp>>SQCX_GB_SHIFT)&SQCX_GB_MSK);	tmp &= ~(SQCX_GB_MSK<<SQCX_GB_SHIFT);	int qStyle = tmp;        if(mainh){            // If main header is being read, set default for component in all            // tiles            switch (qStyle) {            case SQCX_NO_QUANTIZATION:                decSpec.qts.setCompDef(cComp,"reversible");                break;            case SQCX_SCALAR_DERIVED:                decSpec.qts.setCompDef(cComp,"derived");                break;            case SQCX_SCALAR_EXPOUNDED:                decSpec.qts.setCompDef(cComp,"expounded");                break;            default:                throw new CorruptedCodestreamException("Unknown or "+                                                       "unsupported "+                                                       "quantization style "+                                                       "in Sqcd field, QCD "+                                                       "marker, main header");            }        }else{            // If tile header is being read, set value for component in            // this tiles            switch (qStyle) {            case SQCX_NO_QUANTIZATION:                decSpec.qts.setTileCompVal(tileIdx, cComp,"reversible");                break;            case SQCX_SCALAR_DERIVED:                decSpec.qts.setTileCompVal(tileIdx, cComp,"derived");                break;            case SQCX_SCALAR_EXPOUNDED:                decSpec.qts.setTileCompVal(tileIdx, cComp,"expounded");                break;            default:                throw new CorruptedCodestreamException("Unknown or "+                                                       "unsupported "+                                                       "quantization style "+                                                       "in Sqcd field, QCD "+                                                       "marker, main header");            }        }	// Decode all dequantizer params        qParms = new StdDequantizerParams();        if (qStyle == SQCX_NO_QUANTIZATION) {	    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;        	    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];                for(j=minb; j<maxb; j++) {                    tmp = ehs.readUnsignedByte();		    expC[rl][j] = (tmp>>SQCX_EXP_SHIFT)&SQCX_EXP_MASK;                }// end for j            }// end for rl	}

⌨️ 快捷键说明

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