cblkratediststats.java
来自「jpeg2000编解码」· Java 代码 · 共 371 行 · 第 1/2 页
JAVA
371 行
* * @param inclast If false the convex hull is constructed as for lossy * coding. If true it is constructed as for lossless coding, in which case * it is ensured that all bit-planes are sent (i.e. the last truncation * point is always included). * */ public CBlkRateDistStats(int m, int n, int skipMSBP, byte data[], int rates[], double dists[], boolean termp[], int np, boolean inclast) { super(m,n,skipMSBP,data); selectConvexHull(rates,dists,termp,np,inclast); } /** * Compute the rate-distorsion slopes and selects those that lie in a * convex hull. It will compute the slopes, select the ones that form the * convex hull and initialize the 'truncIdxs' and 'truncSlopes' arrays, as * well as 'nVldTrunc', with the selected truncation points. It will also * initialize 'truncRates' and 'isTermPass' arrays, as well as * 'nTotTrunc', with all the truncation points (selected or not). * * <p> Note that the arrays 'rates' and 'termp' are copied, not * referenced, so they can be modified after a call to this method.</p> * * @param rates The rates (in bytes) for each truncation point in the * compressed data. This array is modified by the method. * * @param dists The reduction in distortion (with respect to no * information coded) for each truncation point. This array is modified by * the method. * * @param termp An array of boolean flags indicating, for each pass, if a * pass is terminated or not (true if terminated). If null then it is * assumed that no pass is terminated except the last one which always is. * * @param n The number of truncation points contained in 'rates', 'dist' * and 'termp'. * * @param inclast If false the convex hull is constructed as for lossy * coding. If true it is constructed as for lossless coding, in which case * it is ensured that all bit-planes are sent (i.e. the last truncation * point is always included). * */ public void selectConvexHull(int rates[], double dists[], boolean termp[], int n, boolean inclast) { int first_pnt; // The first point containing some coded data int p; // last selected point int k; // current point int i; // current valid point int npnt; // number of selected (i.e. valid) points int delta_rate; // Rate difference double delta_dist; // Distortion difference float k_slope; // R-D slope for the current point float p_slope; // R-D slope for the last selected point int ll_rate; // Rate for "lossless" coding (i.e. all coded info) // Convention: when a negative value is stored in 'rates' it meas an // invalid point. The absolute value is always the rate for that point. // Look for first point with some coded info (rate not 0) first_pnt = 0; while (first_pnt < n && rates[first_pnt] <= 0) { first_pnt++; } // Select the valid points npnt = n-first_pnt; p_slope = 0f; // To keep compiler happyploop: do { p = -1; for (k=first_pnt; k<n; k++) { if (rates[k] < 0) { // Already invalidated point continue; } // Calculate decrease in distortion and rate if (p >= 0) { delta_rate = rates[k]-rates[p]; delta_dist = dists[k]-dists[p]; } else { // This is with respect to no info coded delta_rate = rates[k]; delta_dist = dists[k]; } // If exactly same distortion don't eliminate if the rates are // equal, otherwise it can lead to infinite slope in lossless // coding. if (delta_dist < 0f || (delta_dist == 0f && delta_rate > 0)) { // This point increases distortion => invalidate rates[k] = -rates[k]; npnt--; continue; // Goto next point } k_slope = (float)(delta_dist/delta_rate); // Check that there is a decrease in distortion, slope is not // infinite (i.e. delta_dist is not 0) and slope is // decreasing. if (p>=0 && (delta_rate <= 0 || k_slope >= p_slope )) { // Last point was not good rates[p] = -rates[p]; // Remove p from valid points npnt--; continue ploop; // Restart from the first one } else { p_slope = k_slope; p = k; } } // If we get to last point we are done break; } while (true); // We end the loop with the break statement // If in lossless mode make sure we don't eliminate any last // bit-planes from being sent. if (inclast && n > 0 && rates[n-1] < 0) { rates[n-1] = -rates[n-1]; // This rate can never be equal to any previous selected rate, // given the selection algorithm above, so no problem arises of // infinite slopes. npnt++; } // Initialize the arrays of this object nTotTrunc = n; nVldTrunc = npnt; truncRates = new int[n]; truncDists = new double[n]; truncSlopes = new float[npnt]; truncIdxs = new int[npnt]; if (termp != null) { isTermPass = new boolean[n]; System.arraycopy(termp,0,isTermPass,0,n); } else { isTermPass = null; } System.arraycopy(rates,0,truncRates,0,n); for (k=first_pnt, p=-1, i=0; k<n; k++) { if (rates[k]>0) { // A valid point truncDists[k] = dists[k]; if (p<0) { // Only arrives at first valid point truncSlopes[i] = (float)(dists[k]/rates[k]); } else { truncSlopes[i] = (float)((dists[k]-dists[p])/ (rates[k]-rates[p])); } truncIdxs[i] = k; i++; p = k; } else { truncDists[k] = -1; truncRates[k] = -truncRates[k]; } } } /** * Returns the contents of the object in a string. This is used for * debugging. * * @return A string with the contents of the object * */ public String toString() { String str = super.toString() + "\n nVldTrunc="+nVldTrunc+", nTotTrunc="+nTotTrunc+", num. ROI"+ " coeff="+nROIcoeff+", num. ROI coding passes="+nROIcp+", sb="+ sb.sbandIdx; str += ",scrambled="+scrambled+",scramblingType="+scramblingType+ ",seed="+seed+",scrambOff="+scrambOff+",lastContribIdx="+ lastContribIdx; str += "\n\ttruncRates:\n"; for(int i=0; i<truncRates.length; i++) { str += "\t "+i+": "+truncRates[i]+"\n"; } str += "\n\ttruncIdxs:\n"; for(int i=0; i<nVldTrunc; i++) { str += "\t "+i+" -> "+truncIdxs[i]+"\n"; } return str; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?