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

📄 headerdecoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                // Remove flag                cstyle &= ~(SCOX_USE_SOP);            } else {                // SOP markers are not used                decSpec.sops.setDefault(new Boolean("false"));            }        } else {            hi.cod.put("t"+tileIdx,ms);            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"));            }        }        // Code-block partition origin        if( (cstyle&(SCOX_HOR_CB_PART|SCOX_VER_CB_PART)) != 0) {            FacilityManager.getMsgLogger().                printmsg(MsgLogger.WARNING,"Code-block partition origin "+                         "different from (0,0). This is defined in JPEG 2000"+                         " part 2 and may not be supported by all JPEG "+                         "2000 decoders.");        }        if( (cstyle&SCOX_HOR_CB_PART)!= 0) {            if(cb0x!=-1 && cb0x==0) {                throw new IllegalArgumentException("Code-block partition "+                                                   "origin redefined in new"+                                                   " COD marker segment. Not"+                                                   " supported by JJ2000");            }            cb0x = 1;            cstyle &= ~(SCOX_HOR_CB_PART);        } else {            if(cb0x!=-1 && cb0x==1) {                throw new IllegalArgumentException("Code-block partition "+                                                   "origin redefined in new"+                                                   " COD marker segment. Not"+                                                   " supported by JJ2000");            }            cb0x = 0;        }        if( (cstyle&SCOX_VER_CB_PART)!= 0) {            if(cb0y!=-1 && cb0y==0) {                throw new IllegalArgumentException("Code-block partition "+                                                   "origin redefined in new"+                                                   " COD marker segment. Not"+                                                   " supported by JJ2000");            }            cb0y = 1;            cstyle &= ~(SCOX_VER_CB_PART);        } else {            if(cb0y!=-1 && cb0y==1) {                throw new IllegalArgumentException("Code-block partition "+                                                   "origin redefined in new"+                                                   " COD marker segment. Not"+                                                   " supported by JJ2000");            }            cb0y = 0;        }        // SGcod        // Read the progressive order        ms.sgcod_po = ehs.readUnsignedByte();        // Read the number of layers        ms.sgcod_nl = ehs.readUnsignedShort();        if (ms.sgcod_nl<=0 || ms.sgcod_nl>65535 ) {            throw new CorruptedCodestreamException("Number of layers out of "+                                                   "range: 1--65535");        }            	// Multiple component transform	ms.sgcod_mct = ehs.readUnsignedByte();	                // SPcod        // decomposition levels        int mrl = ms.spcod_ndl = 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];        ms.spcod_cw = ehs.readUnsignedByte();        cblk[0] = new Integer(1<<(ms.spcod_cw+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);        }        ms.spcod_ch = ehs.readUnsignedByte();        cblk[1] = new Integer(1<<(ms.spcod_ch+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 = ms.spcod_cs = ehs.readUnsignedByte();        if ((ecOptions &             ~(OPT_BYPASS|OPT_RESET_MQ|OPT_TERM_PASS|	       OPT_VERT_STR_CAUSAL|OPT_PRED_TERM | OPT_SEG_SYMBOLS)) != 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,ms.spcod_t);	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 {            ms.spcod_ps = new int[mrl+1];            for (int rl=mrl ;rl>=0 ;rl--) {                Integer w, h;                val = ms.spcod_ps[mrl-rl] = 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(ms.sgcod_mct));            decSpec.nls.setDefault(new Integer(ms.sgcod_nl));            decSpec.pos.setDefault(new Integer(ms.sgcod_po));	}        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(ms.sgcod_mct));            decSpec.nls.setTileDef(tileIdx,new Integer(ms.sgcod_nl));            decSpec.pos.setTileDef(tileIdx,new Integer(ms.sgcod_po));        }    }    /**     * 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 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 readCOC (DataInputStream ehs, boolean mainh, int tileIdx,                          int tpIdx) throws IOException {        int cComp;         // current component        SynWTFilter hfilters[],vfilters[];        int tmp,l;        int ecOptions;        Integer cblk[];        String errMsg;        HeaderInfo.COC ms = hi.getNewCOC();	// Lcoc (marker length)        ms.lcoc = ehs.readUnsignedShort();        // Ccoc        if (nComp < 257) {            cComp = ms.ccoc = ehs.readUnsignedByte();        } else {            cComp = ms.ccoc = ehs.readUnsignedShort();        }        if (cComp >= nComp) {            throw new CorruptedCodestreamException("Invalid component index "+						   "in QCC marker");        }	// Scoc (block style)	int cstyle = ms.scoc = ehs.readUnsignedByte();        if( (cstyle&SCOX_PRECINCT_PARTITION) != 0 ){            precinctPartitionIsUsed = true;            // Remove flag            cstyle &= ~(SCOX_PRECINCT_PARTITION);        } else {            precinctPartitionIsUsed = false;        }        // SPcoc	// decomposition levels        int mrl = ms.spcoc_ndl = ehs.readUnsignedByte();        // Read the code-blocks dimensions        cblk = new Integer[2];        ms.spcoc_cw = ehs.readUnsignedByte();        cblk[0] = new Integer(1<<(ms.spcoc_cw+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, "+                "COC marker";            throw new CorruptedCodestreamException(errMsg);        }        ms.spcoc_ch = ehs.readUnsignedByte();        cblk[1] = new Integer(1<<(ms.spcoc_ch+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, "+                "COC 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, "+                "COC marker";            throw new CorruptedCodestreamException(errMsg);        }        if ( mainh ) {            decSpec.cblks.setCompDef(cComp,cblk);        } else {            decSpec.cblks.setTileCompVal(tileIdx,cComp,cblk);        }        // Read entropy block mode options        // NOTE: currently OPT_SEG_SYMBOLS is not included here        ecOptions = ms.spcoc_cs = ehs.readUnsignedByte();        if ((ecOptions &             ~(OPT_BYPASS|OPT_RESET_MQ|OPT_TERM_PASS|	       OPT_VERT_STR_CAUSAL|OPT_PRED_TERM|OPT_SEG_SYMBOLS)) != 0){            throw                new CorruptedCodestreamException("Unknown \"code-block "+                                                 "context\" in SPcoc field, "+                                                 "COC marker: 0x"+                                                 Integer.                                                 toHexString(ecOptions));        }        // Read wavelet filter for tile or image	hfilters = new SynWTFilter[1];	vfilters = new SynWTFilter[1];	hfilters[0] = readFilter(ehs,ms.spcoc_t);	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 {            ms.spcoc_ps = new int[mrl+1];            for ( int rl=mrl ; rl>=0 ; rl-- ) {                Integer w, h;                val = ms.spcoc_ps[rl] = 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.setCompDef(cComp,v);        } else {            decSpec.pss.setTileCompVal(tileIdx,cComp,v);        }	precinctPartitionIsUsed = true;        // Check marker length        checkMarkerLength(ehs,"COD marker");        if(mainh){            hi.coc.put("main_c"+cComp,ms);            decSpec.wfs.setCompDef(cComp,hvfilters);

⌨️ 快捷键说明

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