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

📄 headerdecoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            hi.qcd.put("t"+tileIdx,ms);            // If the tile header is being read set default value of            // dequantization spec for tile            switch (qType) {            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(qType == SQCX_NO_QUANTIZATION) {	    int maxrl =                 ( 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][];            ms.spqcd = new int[maxrl+1][4];                        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 = ms.spqcd[rl][j] = ehs.readUnsignedByte();		    exp[rl][j] = (tmp>>SQCX_EXP_SHIFT)&SQCX_EXP_MASK;                }            }// end for rl	} else {	    int maxrl = (qType == 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][];            ms.spqcd = new int[maxrl+1][4];            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 = ms.spqcd[rl][j] = 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 rl        } // end if (qType != 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");    }    /**     * Reads a QCC marker segment and realigns the codestream at the point     * where the next marker should be found. QCC is a functional marker     * segment that describes the quantization of one component.     *      * @param ehs The encoded stream.     *     * @param mainh Flag indicating whether or not this marker segment is read     * from the main header.     *     * @param tileIdx The index of the current tile     *     * @param tpIdx Tile-part index     *     * @exception IOException If an I/O error occurs while reading from the     * encoded header stream.     * */    private void readQCC (DataInputStream ehs, boolean mainh, int tileIdx,                           int tpIdx) throws IOException {        int cComp;          // current component        int tmp;	StdDequantizerParams qParms;	int[][] expC;	float[][] nStepC = null;        HeaderInfo.QCC ms = hi.getNewQCC();	// Lqcc (length of QCC field)	ms.lqcc = ehs.readUnsignedShort();	        // Cqcc        if (nComp < 257) {            cComp = ms.cqcc = ehs.readUnsignedByte();        } else {            cComp = ms.cqcc = ehs.readUnsignedShort();        }        if (cComp >= nComp) {            throw new CorruptedCodestreamException("Invalid component "+                                                   "index in QCC marker");        }		// Sqcc (quantization style)	ms.sqcc = ehs.readUnsignedByte();	int guardBits = ms.getNumGuardBits();	int qType = ms.getQuantType();        if(mainh) {            hi.qcc.put("main_c"+cComp,ms);            // If main header is being read, set default for component in all            // tiles            switch (qType) {            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 {            hi.qcc.put("t"+tileIdx+"_c"+cComp,ms);            // If tile header is being read, set value for component in            // this tiles            switch (qType) {            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 (qType == SQCX_NO_QUANTIZATION) {	    int maxrl = ( 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][];            ms.spqcc = new int[maxrl+1][4];            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 = ms.spqcc[rl][j] = ehs.readUnsignedByte();		    expC[rl][j] = (tmp>>SQCX_EXP_SHIFT)&SQCX_EXP_MASK;                }            }// end for rl	} else {	    int maxrl = (qType == 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][];            ms.spqcc = new int[maxrl+1][4];            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 = ms.spqcc[rl][j] = 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 rl        } // end if (qType != 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");    }    /**     * Reads a COD 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 this marker segment is read     * from the main header.     *     * @param tileIdx The index of the current tile     *     * @param tpIdx Tile-part index     *     * @exception IOException If an I/O error occurs while reading from the     * encoder header stream     * */    private void readCOD (DataInputStream ehs, boolean mainh, int tileIdx,                           int tpIdx) throws IOException {        int cstyle;         // The block style        SynWTFilter hfilters[],vfilters[];        int l;        Integer cblk[];        String errMsg;        boolean sopUsed = false;        boolean ephUsed = false;        HeaderInfo.COD ms = hi.getNewCOD();        // Lcod (marker length)        ms.lcod = ehs.readUnsignedShort();        // Scod (block style)        // We only support wavelet transformed data        cstyle = ms.scod = ehs.readUnsignedByte();        if( (cstyle&SCOX_PRECINCT_PARTITION) != 0 ){            precinctPartitionIsUsed = true;            // Remove flag            cstyle &= ~(SCOX_PRECINCT_PARTITION);        } else {            precinctPartitionIsUsed = false;        }         // SOP markers        if (mainh) {            hi.cod.put("main",ms);            if( (cstyle&SCOX_USE_SOP) != 0 ){                // SOP markers are used                decSpec.sops.setDefault(new Boolean("true"));                sopUsed = true;

⌨️ 快捷键说明

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