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

📄 headerencoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if ( lenCompField==2 ) {                hbuf.writeShort(prog[i].ce);            } else {                hbuf.write(prog[i].ce);            }            // Ppoc(i)            hbuf.write(prog[i].type);        }    }    /**     * Write main header. JJ2000 main header corresponds to the following     * sequence of marker segments:     *     * <ol>     * <li>SOC</li>     * <li>SIZ</li>     * <li>COD</li>     * <li>COC (if needed)</li>     * <li>QCD</li>     * <li>QCC (if needed)</li>     * <li>POC (if needed)</li>     * </ol>     * */    public void encodeMainHeader() throws IOException {        int i;	        // +---------------------------------+        // |    SOC marker segment           |        // +---------------------------------+        writeSOC();        // +---------------------------------+        // |    Image and tile SIZe (SIZ)    |        // +---------------------------------+        writeSIZ();        // +-------------------------------+        // |   COding style Default (COD)  |        // +-------------------------------+        boolean isEresUsed = ((String)encSpec.tts.getDefault()).            equals("predict");        writeCOD(true,0);                    // +---------------------------------+        // |   COding style Component (COC)  |        // +---------------------------------+	for (i= 0; i<nComp; i++) {            boolean isEresUsedinComp = ((String)encSpec.tts.getCompDef(i)).                equals("predict");	    if(encSpec.wfs.isCompSpecified(i) ||               encSpec.dls.isCompSpecified(i) ||               encSpec.bms.isCompSpecified(i) ||               encSpec.mqrs.isCompSpecified(i) ||               encSpec.rts.isCompSpecified(i) ||               encSpec.sss.isCompSpecified(i) ||               encSpec.css.isCompSpecified(i) ||               encSpec.pss.isCompSpecified(i) ||               encSpec.cblks.isCompSpecified(i) ||               (isEresUsed != isEresUsedinComp ) )		// Some component non-default stuff => need COC		writeCOC(true,0,i);        }        // +-------------------------------+        // |   Quantization Default (QCD)  |        // +-------------------------------+        writeMainQCD();        // +-------------------------------+        // | Quantization Component (QCC)  |        // +-------------------------------+        // Write needed QCC markers        for(i=0; i<nComp; i++) {	    if(dwt.getNomRangeBits(i)!= defimgn ||	       encSpec.qts.isCompSpecified(i) ||                encSpec.qsss.isCompSpecified(i) ||               encSpec.dls.isCompSpecified(i) ||               encSpec.gbs.isCompSpecified(i)) {                writeMainQCC(i);	    }        }        // +--------------------------+        // |    POC maker segment     |	// +--------------------------+	Progression[] prog = (Progression[])(encSpec.pocs.getDefault());        if(prog.length>1)            writePOC(true, 0);        // +---------------------------+        // |      Comments (COM)       |        // +---------------------------+        writeCOM();    }    /**      * Write COM marker segment(s) to the codestream.     *      * <p>This marker is currently written in main header and indicates the     * JJ2000 encoder's version that has created the codestream.</p>     * */    private void writeCOM() throws IOException {        // JJ2000 COM marker segment        if(enJJ2KMarkSeg) {            String str = "Created by: JJ2000 version "+JJ2KInfo.version;            int markSegLen; // the marker segment length                        // COM marker            hbuf.writeShort(COM);                        // Calculate length: Lcom(2) + Rcom (2) + string's length;            markSegLen = 2 + 2 + str.length();            hbuf.writeShort(markSegLen);                        // Rcom             hbuf.writeShort(1); // General use (IS 8859-15:1999(Latin) values)                        byte[] chars = str.getBytes();            for(int i=0; i<chars.length; i++) {                hbuf.writeByte(chars[i]);            }        }        // other COM marker segments        if(otherCOMMarkSeg!=null) {            StringTokenizer stk = new StringTokenizer(otherCOMMarkSeg,"#");            while(stk.hasMoreTokens()) {                String str = stk.nextToken();                int markSegLen; // the marker segment length                            // COM marker                hbuf.writeShort(COM);                                // Calculate length: Lcom(2) + Rcom (2) + string's length;                markSegLen = 2 + 2 + str.length();                hbuf.writeShort(markSegLen);                                // Rcom                 hbuf.writeShort(1); // General use (IS 8859-15:1999(Latin)                // values)                                byte[] chars = str.getBytes();                for(int i=0; i<chars.length; i++) {                    hbuf.writeByte(chars[i]);                }            }        }    }    /**     * Writes the RGN marker segment in the tile header. It describes the     * scaling value in each tile component     *     * <p>May be used in tile or main header. If used in main header, it     * refers to a ROI of the whole image, regardless of tiling. When used in     * tile header, only the particular tile is affected.</p>     *     * @param tIdx The tile index      *     * @exception IOException If an I/O error occurs while reading from the     * encoder header stream     * */    private void writeRGN(int tIdx) throws IOException {        int i;        int markSegLen;    // the marker length        // Write one RGN marker per component         for(i=0;i<nComp;i++) {            // RGN marker            hbuf.writeShort(RGN);                        // Calculate length (Lrgn)            // Basic: Lrgn (2) + Srgn (1) + SPrgn + one byte             // or two for component number            markSegLen = 4+((nComp<257)? 1:2);            hbuf.writeShort(markSegLen);                        // Write component (Crgn)            if(nComp<257) {                hbuf.writeByte(i);            } else {                hbuf.writeShort(i);            }                        // Write type of ROI (Srgn)             hbuf.writeByte(SRGN_IMPLICIT);                        // Write ROI info (SPrgn)            hbuf.writeByte(((Integer)(encSpec.rois.			      getTileCompVal(tIdx,i))).intValue());        }    }    /**      * Writes tile-part header. JJ2000 tile-part header corresponds to the     * following sequence of marker segments:     *     * <ol>      * <li>SOT</li>      * <li>COD (if needed)</li>      * <li>COC (if needed)</li>      * <li>QCD (if needed)</li>      * <li>QCC (if needed)</li>      * <li>RGN (if needed)</li>      * <li>POC (if needed)</li>     * <li>SOD</li>      * </ol>     *     * @param length The length of the current tile-part.     *     * @param tileIdx Index of the tile to write     * */    public void encodeTilePartHeader(int tileLength,int tileIdx)         throws IOException {                        int tmp;        Coord numTiles = ralloc.getNumTiles(null);        ralloc.setTile(tileIdx%numTiles.x,tileIdx/numTiles.x);          	// +--------------------------+        // |    SOT maker segment     |	// +--------------------------+        // SOT marker        hbuf.writeByte(SOT>>8);        hbuf.writeByte(SOT);                    // Lsot (10 bytes)        hbuf.writeByte(0);        hbuf.writeByte(10);                    // Isot        if(tileIdx>65534) {            throw new IllegalArgumentException("Trying to write a tile-part "+                                               "header whose tile index is "+                                               "too high");        }        hbuf.writeByte(tileIdx>>8);        hbuf.writeByte(tileIdx);                // Psot        tmp = tileLength;        hbuf.writeByte(tmp>>24);        hbuf.writeByte(tmp>>16);        hbuf.writeByte(tmp>>8);        hbuf.writeByte(tmp);                // TPsot        hbuf.writeByte(0); // Only one tile-part currently supported !	// TNsot	hbuf.writeByte(1); // Only one tile-part currently supported !        	// +--------------------------+        // |    COD maker segment     |	// +--------------------------+        boolean isEresUsed = ((String)encSpec.tts.getDefault()).            equals("predict");        boolean isEresUsedInTile = ((String)encSpec.tts.getTileDef(tileIdx)).            equals("predict");        boolean tileCODwritten = false;	if(encSpec.wfs.isTileSpecified(tileIdx) ||           encSpec.cts.isTileSpecified(tileIdx) ||           encSpec.dls.isTileSpecified(tileIdx) ||           encSpec.bms.isTileSpecified(tileIdx) ||           encSpec.mqrs.isTileSpecified(tileIdx) ||           encSpec.rts.isTileSpecified(tileIdx) ||           encSpec.css.isTileSpecified(tileIdx) ||           encSpec.pss.isTileSpecified(tileIdx) ||           encSpec.sops.isTileSpecified(tileIdx) ||           encSpec.sss.isTileSpecified(tileIdx) ||           encSpec.pocs.isTileSpecified(tileIdx) ||           encSpec.ephs.isTileSpecified(tileIdx) ||           encSpec.cblks.isTileSpecified(tileIdx) ||           ( isEresUsed != isEresUsedInTile ) ) {	    writeCOD(false,tileIdx);            tileCODwritten = true;	}	// +--------------------------+        // |    COC maker segment     |	// +--------------------------+	for(int c=0; c<nComp; c++) {            boolean isEresUsedInTileComp = ((String)encSpec.tts.                                            getTileCompVal(tileIdx,c)).		equals("predict");	    if(encSpec.wfs.isTileCompSpecified(tileIdx,c) ||               encSpec.dls.isTileCompSpecified(tileIdx,c) ||               encSpec.bms.isTileCompSpecified(tileIdx,c) ||               encSpec.mqrs.isTileCompSpecified(tileIdx,c) ||               encSpec.rts.isTileCompSpecified(tileIdx,c) ||               encSpec.css.isTileCompSpecified(tileIdx,c) ||               encSpec.pss.isTileCompSpecified(tileIdx,c) ||               encSpec.sss.isTileCompSpecified(tileIdx,c) ||               encSpec.cblks.isTileCompSpecified(tileIdx,c) ||               ( isEresUsedInTileComp != isEresUsed ) ) {		writeCOC(false,tileIdx,c);	    } else if(tileCODwritten) {                if(encSpec.wfs.isCompSpecified(c) ||                   encSpec.dls.isCompSpecified(c) ||                   encSpec.bms.isCompSpecified(c) ||                   encSpec.mqrs.isCompSpecified(c) ||                   encSpec.rts.isCompSpecified(c) ||                   encSpec.sss.isCompSpecified(c) ||                   encSpec.css.isCompSpecified(c) ||                   encSpec.pss.isCompSpecified(c) ||                   encSpec.cblks.isCompSpecified(c) ||                   (encSpec.tts.isCompSpecified(c)&&                    ((String)encSpec.tts.getCompDef(c)).equals("predict"))) {                    writeCOC(false,tileIdx,c);                }            }        }	// +--------------------------+        // |    QCD maker segment     |	// +--------------------------+        boolean tileQCDwritten = false;	if(encSpec.qts.isTileSpecified(tileIdx) ||           encSpec.qsss.isTileSpecified(tileIdx) ||           encSpec.dls.isTileSpecified(tileIdx) ||           encSpec.gbs.isTileSpecified(tileIdx)) {	    writeTileQCD(tileIdx);            tileQCDwritten = true;	} else {            deftilenr = defimgn;        }		// +--------------------------+        // |    QCC maker segment     |	// +--------------------------+	for(int c=0; c<nComp; c++) {	    if(dwt.getNomRangeBits(c)!= deftilenr ||               encSpec.qts.isTileCompSpecified(tileIdx,c) ||               encSpec.qsss.isTileCompSpecified(tileIdx,c) ||               encSpec.dls.isTileCompSpecified(tileIdx,c) ||               encSpec.gbs.isTileCompSpecified(tileIdx,c)) {		writeTileQCC(tileIdx,c);	    } else if(tileQCDwritten) {                if(encSpec.qts.isCompSpecified(c) ||                    encSpec.qsss.isCompSpecified(c) ||                   encSpec.dls.isCompSpecified(c) ||                   encSpec.gbs.isCompSpecified(c)) {                    writeTileQCC(tileIdx,c);                }            }	}	// +--------------------------+        // |    RGN maker segment     |	// +--------------------------+        if(roiSc.useRoi() &&(!roiSc.getBlockAligned()))            writeRGN(tileIdx);      	// +--------------------------+        // |    POC maker segment     |	// +--------------------------+	Progression[] prog;        if( encSpec.pocs.isTileSpecified(tileIdx) ) {	    prog = (Progression[])(encSpec.pocs.getTileDef(tileIdx));	    if(prog.length>1)                writePOC(false,tileIdx);        }	// +--------------------------+        // |         SOD maker        |	// +--------------------------+        hbuf.writeByte(SOD>>8);        hbuf.writeByte(SOD);    } }

⌨️ 快捷键说明

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