📄 headerencoder.java
字号:
* @param tileIdx Tile index if the marker belongs to a tile-part header * * @see #writeCOC * */ protected void writeCOD(boolean mh, int tileIdx) 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.getDefault()).intValue(); // get default precinct size ppx = encSpec.pss.getPPX(-1,-1,mrl); ppy = encSpec.pss.getPPY(-1,-1,mrl); prog = (Progression[])(encSpec.pocs.getDefault()); } else { mrl = ((Integer)encSpec.dls.getTileDef(tileIdx)).intValue(); // get precinct size for specified tile ppx = encSpec.pss.getPPX(tileIdx,-1,mrl); ppy = encSpec.pss.getPPY(tileIdx,-1,mrl); prog = (Progression[])(encSpec.pocs.getTileDef(tileIdx)); } if(ppx!=PRECINCT_PARTITION_DEF_SIZE || ppy!=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; } // Write COD marker hbuf.writeShort(COD); // Lcod (marker segment length (in bytes)) Basic : Lcod(2 // bytes)+Scod(1)+SGcod(4)+SPcod(5+a) where: // a=0 if no precinct partition is used // a=mrl+1 if precinct partition used int markSegLen = 12+a; hbuf.writeShort(markSegLen); // Scod (coding style parameter) tmp=0; if(precinctPartitionUsed) { tmp=SCOX_PRECINCT_PARTITION; } // Are SOP markers used ? if(mh) { if( ((String)encSpec.sops.getDefault().toString()) .equalsIgnoreCase("on") ) { tmp |= SCOX_USE_SOP; } } else { if( ((String)encSpec.sops.getTileDef(tileIdx).toString()) .equalsIgnoreCase("on") ) { tmp |= SCOX_USE_SOP; } } // Are EPH markers used ? if(mh) { if ( ((String)encSpec.ephs.getDefault().toString()) .equalsIgnoreCase("on") ) { tmp |= SCOX_USE_EPH; } } else { if ( ((String)encSpec.ephs.getTileDef(tileIdx).toString()) .equalsIgnoreCase("on") ) { tmp |= SCOX_USE_EPH; } } if (dwt.getCbULX()!=0) tmp |= SCOX_HOR_CB_PART; if (dwt.getCbULY()!=0) tmp |= SCOX_VER_CB_PART; hbuf.write(tmp); // SGcod // Progression order hbuf.write(prog[0].type); // Number of layers hbuf.writeShort(ralloc.getNumLayers()); // Multiple component transform // CSsiz (Color transform) String str = null; if(mh) { str = (String)encSpec.cts.getDefault(); } else { str = (String)encSpec.cts.getTileDef(tileIdx); } if(str.equals("none")) { hbuf.write(0); } else { hbuf.write(1); } // SPcod // Number of decomposition levels hbuf.write(mrl); // Code-block width and height if(mh) { // main header, get default values tmp = encSpec.cblks. getCBlkWidth(ModuleSpec.SPEC_DEF,-1,-1); 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_TERM_PASS; } // 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_PRED_TERM; } // Error resilience segmentation symbol insertion ? if( ((String)encSpec.sss.getDefault()).equals("on")) { tmp |= OPT_SEG_SYMBOLS; } } 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_TERM_PASS; } // 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_PRED_TERM; } // Error resilience segmentation symbol insertion ? if( ((String)encSpec.sss.getTileDef(tileIdx)).equals("on")) { tmp |= OPT_SEG_SYMBOLS; } } 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.</p> * * @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.pocs.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.pocs. 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_TERM_PASS; } // 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_PRED_TERM; } // Error resilience segmentation symbol insertion ? if( ((String)encSpec.sss.getCompDef(compIdx)).equals("on")) { tmp |= OPT_SEG_SYMBOLS; } } 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_TERM_PASS; } // Vertically stripe-causal context mode ? if( ((String)encSpec.css.getTileCompVal(tileIdx,compIdx)). equals("on") ) { tmp |= OPT_VERT_STR_CAUSAL; } // Predictable termination ?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -