📄 headerencoder.java
字号:
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,tIdx; float step; SubbandAn sb,sb2; SubbandAn sbRoot; if(encSpec.qts.isCompSpecified(compIdx)){ tIdx = encSpec.qts.getCompDefRep(compIdx); } else{ tIdx = encSpec.qts.getDefRep()[0]; } sbRoot = dwt.getSubbandTree(tIdx,compIdx); 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 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. 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 c; int mrl; int qstyle; float step; SubbandAn sb,csb,sbRoot; if(encSpec.qts.isTileSpecified(tIdx)){ int cIdx = encSpec.qts.getTileDefRep(tIdx); sbRoot = dwt.getSubbandTree(tIdx,cIdx); deftilenr = dwt.getNomRangeBits(cIdx); } else{ // No quantization type specification for this tile int cIdx = 0; for(cIdx=0; cIdx<nComp; cIdx++){ if(!encSpec.qts.isCompSpecified(cIdx)){ break; } } // All the component are specified if(cIdx>=nComp) throw new IllegalArgumentException("No component default"+ " value"+ " for quantization type"); sbRoot = dwt.getSubbandTree(tIdx,cIdx); deftilenr = dwt.getNomRangeBits(cIdx); } String qType = (String)encSpec.qts.getTileDef(tIdx); float baseStep = ((Float)encSpec.qsss.getTileDef(tIdx)).floatValue(); 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); mrl = ((Integer)encSpec.dls.getTileDef(tIdx)).intValue(); // 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.getSubbandTree(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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -