📄 headerencoder.java
字号:
convertToExpMantissa(step)); sb2 = (SubbandAn)sb2.nextSubband(); } // Go up one resolution level sb = (SubbandAn) sb.getNextResLevel(); } break; default: throw new Error("Internal JJ2000 error"); } } /** * Writes QCD marker segment in tile 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. * * @param tIdx Tile index * */ protected void writeTileQCD(int tIdx) throws IOException { int mrl; int qstyle; float step; SubbandAn sb,csb,sbRoot; String qType = (String)encSpec.qts.getTileDef(tIdx); float baseStep = ((Float)encSpec.qsss.getTileDef(tIdx)).floatValue(); mrl = ((Integer)encSpec.dls.getTileDef(tIdx)).intValue(); int nc = dwt.getNumComps(); int tmpI; String tmpStr; boolean notFound = true; int compIdx = 0; for(int c=0; c<nc && notFound; c++) { tmpI = ((Integer)encSpec.dls.getTileCompVal(tIdx,c)).intValue(); tmpStr = (String)encSpec.qts.getTileCompVal(tIdx,c); if(tmpI==mrl && tmpStr.equals(qType)) { compIdx = c; notFound = false; } } if(notFound) { throw new Error("Default representative for quantization type "+ " and number of decomposition levels not found "+ " in tile QCD (t="+tIdx+") marker segment. "+ "You have found a JJ2000 bug."); } sbRoot = dwt.getAnSubbandTree(tIdx,compIdx); deftilenr = dwt.getNomRangeBits(compIdx); int gb = ((Integer)encSpec.gbs.getTileDef(tIdx)).intValue(); boolean isDerived = qType.equals("derived"); boolean isReversible = qType.equals("reversible"); 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 = (deftilenr+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 tile 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 t Tile index * * @param compIdx Index of the component which needs QCC marker segment. * */ protected void writeTileQCC(int t,int compIdx) throws IOException { int mrl; int qstyle; float step; SubbandAn sb,sb2; int nqcc; // Number of quantization step-size to transmit SubbandAn sbRoot = dwt.getAnSubbandTree(t,compIdx); int imgnr = dwt.getNomRangeBits(compIdx); String qType = (String)encSpec.qts.getTileCompVal(t,compIdx); float baseStep = ((Float)encSpec.qsss.getTileCompVal(t,compIdx)). floatValue(); int gb = ((Integer)encSpec.gbs.getTileCompVal(t,compIdx)).intValue(); boolean isReversible = qType.equals("reversible"); boolean isDerived = qType.equals("derived"); mrl = ((Integer)encSpec.dls.getTileCompVal(t,compIdx)).intValue(); // 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. convertToExpMantissa(step)); sb2 = (SubbandAn)sb2.nextSubband(); } // Go up one resolution level sb = (SubbandAn) sb.getNextResLevel(); } break; default: throw new Error("Internal JJ2000 error"); } } /** * Writes POC marker segment. POC is a functional marker segment * containing the bounds and progression order for any progression order * other than default in the codestream. * * @param mh Flag indicating whether the main header is to be written * * @param tileIdx Tile index * */ protected void writePOC(boolean mh, int tileIdx) throws IOException { int markSegLen=0; // Segment marker length int lenCompField; // Holds the size of any component field as // this size depends on the number of //components Progression[] prog = null; // Holds the progression(s) int npoc; // Number of progression order changes // Get the progression order changes, their number and checks // if it is ok if(mh) { prog = (Progression[])(encSpec.pocs.getDefault()); } else { prog = (Progression[])(encSpec.pocs.getTileDef(tileIdx)); } // Calculate the length of a component field (depends on the number of // components) lenCompField = (nComp<257 ? 1 : 2); // POC marker hbuf.writeShort(POC); // Lpoc (marker segment length (in bytes)) // Basic: Lpoc(2 bytes) + npoc * [ RSpoc(1) + CSpoc(1 or 2) + // LYEpoc(2) + REpoc(1) + CEpoc(1 or 2) + Ppoc(1) ] npoc = prog.length; markSegLen = 2 + npoc * (1+lenCompField+2+1+lenCompField+1); hbuf.writeShort(markSegLen); // Write each progression order change for (int i=0 ; i<npoc ; i++) { // RSpoc(i) hbuf.write(prog[i].rs); // CSpoc(i) if ( lenCompField==2 ) { hbuf.writeShort(prog[i].cs); } else { hbuf.write(prog[i].cs); } // LYEpoc(i) hbuf.writeShort(prog[i].lye); // REpoc(i) hbuf.write(prog[i].re); // CEpoc(i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -