📄 headerencoder.java
字号:
if( ((String)encSpec.tts.getTileCompVal(tileIdx,compIdx)). equals("predict")) { tmp |= OPT_PRED_TERM; } // Error resilience segmentation symbol insertion ? if( ((String)encSpec.sss.getTileCompVal(tileIdx,compIdx)). equals("on")) { tmp |= OPT_SEG_SYMBOLS; } } hbuf.write(tmp); // Wavelet transform // Wavelet Filter if(mh) { filt=((AnWTFilter[][])encSpec.wfs.getCompDef(compIdx)); hbuf.write(filt[0][0].getFilterType()); } else { filt=((AnWTFilter[][])encSpec.wfs.getTileCompVal(tileIdx,compIdx)); 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.getCompDef(compIdx); } else { v = (Vector[])encSpec.pss.getTileCompVal(tileIdx, compIdx); } 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 QCD marker segment in main header. QCD is a functional marker * segment countaining the quantization default used for compressing all * the components in an image. The values can be overriden for an * individual component by a QCC marker in either the main or the tile * header. * */ protected void writeMainQCD() throws IOException { int mrl; int qstyle; float step; String qType = (String)encSpec.qts.getDefault(); float baseStep = ((Float)encSpec.qsss.getDefault()).floatValue(); int gb = ((Integer)encSpec.gbs.getDefault()).intValue(); boolean isDerived = qType.equals("derived"); boolean isReversible = qType.equals("reversible"); mrl = ((Integer)encSpec.dls.getDefault()).intValue(); int nt = dwt.getNumTiles(); int nc = dwt.getNumComps(); int tmpI; int[] tcIdx = new int[2]; String tmpStr; boolean notFound = true; for(int t=0; t<nt && notFound; t++) { for(int c=0; c<nc && notFound; c++) { tmpI = ((Integer)encSpec.dls.getTileCompVal(t,c)).intValue(); tmpStr = (String)encSpec.qts.getTileCompVal(t,c); if(tmpI==mrl && tmpStr.equals(qType)) { tcIdx[0] = t; tcIdx[1] = c; notFound = false; } } } if(notFound) { throw new Error("Default representative for quantization type "+ " and number of decomposition levels not found "+ " in main QCD marker segment. "+ "You have found a JJ2000 bug."); } SubbandAn sb,csb, sbRoot = dwt.getAnSubbandTree(tcIdx[0],tcIdx[1]); defimgn = dwt.getNomRangeBits(tcIdx[1]); int nqcd; // Number of quantization step-size to transmit // Get the quantization style qstyle = (isReversible) ? SQCX_NO_QUANTIZATION : ((isDerived) ? SQCX_SCALAR_DERIVED : SQCX_SCALAR_EXPOUNDED); // QCD marker hbuf.writeShort(QCD); // Compute the number of steps to send switch (qstyle) { case SQCX_SCALAR_DERIVED: nqcd = 1; // Just the LL value break; case SQCX_NO_QUANTIZATION: case SQCX_SCALAR_EXPOUNDED: // One value per subband nqcd=0; sb=sbRoot; // Get the subband at first resolution level sb = (SubbandAn) sb.getSubbandByIdx(0,0); // Count total number of subbands for (int j=0; j<=mrl; j++) { csb = sb; while (csb != null) { nqcd++; csb = (SubbandAn) csb.nextSubband(); } // Go up one resolution level sb = (SubbandAn) sb.getNextResLevel(); } break; default: throw new Error("Internal JJ2000 error"); } // Lqcd (marker segment length (in bytes)) // Lqcd(2 bytes)+Sqcd(1)+ SPqcd (2*Nqcd) int markSegLen = 3 + ((isReversible) ? nqcd : 2*nqcd); // Rounded to the nearest even value greater or equals hbuf.writeShort(markSegLen); // Sqcd hbuf.write(qstyle+(gb<<SQCX_GB_SHIFT)); // SPqcd switch (qstyle) { case SQCX_NO_QUANTIZATION: sb = sbRoot; sb = (SubbandAn)sb.getSubbandByIdx(0,0); // Output one exponent per subband for (int j=0; j<=mrl; j++) { csb = sb; while(csb != null) { int tmp = (defimgn + csb.anGainExp); hbuf.write(tmp<<SQCX_EXP_SHIFT); csb = (SubbandAn)csb.nextSubband(); // Go up one resolution level } sb = (SubbandAn)sb.getNextResLevel(); } break; case SQCX_SCALAR_DERIVED: sb = sbRoot; sb = (SubbandAn)sb.getSubbandByIdx(0,0); // Calculate subband step (normalized to unit // dynamic range) step = baseStep/(1<<sb.level); // Write exponent-mantissa, 16 bits hbuf.writeShort(StdQuantizer. convertToExpMantissa(step)); break; case SQCX_SCALAR_EXPOUNDED: sb = sbRoot; sb = (SubbandAn)sb.getSubbandByIdx(0,0); // Output one step per subband for (int j=0; j<=mrl; j++) { csb = sb; while(csb != null) { // Calculate subband step (normalized to unit // dynamic range) step = baseStep/(csb.l2Norm*(1<<csb.anGainExp)); // Write exponent-mantissa, 16 bits hbuf.writeShort(StdQuantizer. convertToExpMantissa(step)); csb = (SubbandAn)csb.nextSubband(); } // Go up one resolution level sb = (SubbandAn)sb.getNextResLevel(); } break; default: throw new Error("Internal JJ2000 error"); } } /** * Writes QCC marker segment in main header. It is a functional marker * segment countaining the quantization used for compressing the specified * component in an image. The values override for the specified component * what was defined by a QCC marker in either the main or the tile header. * * @param compIdx Index of the component which needs QCC marker segment. * */ protected void writeMainQCC(int compIdx) throws IOException { int mrl; int qstyle; int tIdx = 0; float step; SubbandAn sb,sb2; SubbandAn sbRoot; int imgnr = dwt.getNomRangeBits(compIdx); String qType = (String)encSpec.qts.getCompDef(compIdx); float baseStep = ((Float)encSpec.qsss.getCompDef(compIdx)).floatValue(); int gb = ((Integer)encSpec.gbs.getCompDef(compIdx)).intValue(); boolean isReversible = qType.equals("reversible"); boolean isDerived = qType.equals("derived"); mrl = ((Integer)encSpec.dls.getCompDef(compIdx)).intValue(); int nt = dwt.getNumTiles(); int nc = dwt.getNumComps(); int tmpI; String tmpStr; boolean notFound = true; for(int t=0; t<nt && notFound; t++) { for(int c=0; c<nc && notFound; c++) { tmpI = ((Integer)encSpec.dls.getTileCompVal(t,c)).intValue(); tmpStr = (String)encSpec.qts.getTileCompVal(t,c); if(tmpI==mrl && tmpStr.equals(qType)) { tIdx = t; notFound = false; } } } if(notFound) { throw new Error("Default representative for quantization type "+ " and number of decomposition levels not found "+ " in main QCC (c="+compIdx+") marker segment. "+ "You have found a JJ2000 bug."); } sbRoot = dwt.getAnSubbandTree(tIdx,compIdx); int nqcc; // Number of quantization step-size to transmit // Get the quantization style if(isReversible) { qstyle = SQCX_NO_QUANTIZATION; } else if (isDerived) { qstyle = SQCX_SCALAR_DERIVED; } else { qstyle = SQCX_SCALAR_EXPOUNDED; } // QCC marker hbuf.writeShort(QCC); // Compute the number of steps to send switch (qstyle) { case SQCX_SCALAR_DERIVED: nqcc = 1; // Just the LL value break; case SQCX_NO_QUANTIZATION: case SQCX_SCALAR_EXPOUNDED: // One value per subband nqcc = 0; sb = sbRoot; mrl = sb.resLvl; // Get the subband at first resolution level sb = (SubbandAn)sb.getSubbandByIdx(0,0); // Find root element for LL subband while (sb.resLvl != 0) { sb = sb.subb_LL; } // Count total number of subbands for (int j=0; j<=mrl; j++) { sb2 = sb; while (sb2 != null) { nqcc++; sb2 = (SubbandAn) sb2.nextSubband(); } // Go up one resolution level sb = (SubbandAn) sb.getNextResLevel(); } break; default: throw new Error("Internal JJ2000 error"); } // Lqcc (marker segment length (in bytes)) // Lqcc(2 bytes)+Cqcc(1 or 2)+Sqcc(1)+ SPqcc (2*Nqcc) int markSegLen = 3 + ((nComp < 257) ? 1 : 2) + ((isReversible) ? nqcc : 2*nqcc); hbuf.writeShort(markSegLen); // Cqcc if (nComp < 257) { hbuf.write(compIdx); } else { hbuf.writeShort(compIdx); } // Sqcc (quantization style) hbuf.write(qstyle+(gb<<SQCX_GB_SHIFT)); // SPqcc switch (qstyle) { case SQCX_NO_QUANTIZATION: // Get resolution level 0 subband sb = sbRoot; sb = (SubbandAn) sb.getSubbandByIdx(0,0); // Output one exponent per subband for (int j=0; j<=mrl; j++) { sb2 = sb; while (sb2 != null) { int tmp = (imgnr+sb2.anGainExp); hbuf.write(tmp<<SQCX_EXP_SHIFT); sb2 = (SubbandAn)sb2.nextSubband(); } // Go up one resolution level sb = (SubbandAn)sb.getNextResLevel(); } break; case SQCX_SCALAR_DERIVED: // Get resolution level 0 subband sb = sbRoot; sb = (SubbandAn) sb.getSubbandByIdx(0,0); // Calculate subband step (normalized to unit // dynamic range) step = baseStep/(1<<sb.level); // Write exponent-mantissa, 16 bits hbuf.writeShort(StdQuantizer. convertToExpMantissa(step)); break; case SQCX_SCALAR_EXPOUNDED: // Get resolution level 0 subband sb = sbRoot; mrl = sb.resLvl; sb = (SubbandAn) sb.getSubbandByIdx(0,0); for (int j=0; j<=mrl; j++) { sb2 = sb; while (sb2 != null) { // Calculate subband step (normalized to unit // dynamic range) step = baseStep/(sb2.l2Norm*(1<<sb2.anGainExp)); // Write exponent-mantissa, 16 bits hbuf.writeShort(StdQuantizer.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -