stdentropycoder.java
来自「jpeg2000编解码」· Java 代码 · 共 1,566 行 · 第 1/5 页
JAVA
1,566 行
private static final int STATE_SIG_R1 = 1<<15; /** The flag bit for the "visited" bit in the state array, for row 1. */ private static final int STATE_VISITED_R1 = 1<<14; /** The flag bit for the "not zero context" bit in the state array, for * row 1. This bit is always the OR of bits STATE_H_L_R1, STATE_H_R_R1, * STATE_V_U_R1, STATE_V_D_R1, STATE_D_UL_R1, STATE_D_UR_R1, STATE_D_DL_R1 * and STATE_D_DR_R1. */ private static final int STATE_NZ_CTXT_R1 = 1<<13; /** The flag bit for the horizontal-left sign in the state array, for row * 1. This bit can only be set if the STATE_H_L_R1 is also set. */ private static final int STATE_H_L_SIGN_R1 = 1<<12; /** The flag bit for the horizontal-right sign in the state array, for * row 1. This bit can only be set if the STATE_H_R_R1 is also set. */ private static final int STATE_H_R_SIGN_R1 = 1<<11; /** The flag bit for the vertical-up sign in the state array, for row * 1. This bit can only be set if the STATE_V_U_R1 is also set. */ private static final int STATE_V_U_SIGN_R1 = 1<<10; /** The flag bit for the vertical-down sign in the state array, for row * 1. This bit can only be set if the STATE_V_D_R1 is also set. */ private static final int STATE_V_D_SIGN_R1 = 1<<9; /** The flag bit for the previous MR primitive applied in the state array, for row 1. */ private static final int STATE_PREV_MR_R1 = 1<<8; /** The flag bit for the horizontal-left significance in the state array, for row 1. */ private static final int STATE_H_L_R1 = 1<<7; /** The flag bit for the horizontal-right significance in the state array, for row 1. */ private static final int STATE_H_R_R1 = 1<<6; /** The flag bit for the vertical-up significance in the state array, for row 1. */ private static final int STATE_V_U_R1 = 1<<5; /** The flag bit for the vertical-down significance in the state array, for row 1. */ private static final int STATE_V_D_R1 = 1<<4; /** The flag bit for the diagonal up-left significance in the state array, for row 1. */ private static final int STATE_D_UL_R1 = 1<<3; /** The flag bit for the diagonal up-right significance in the state array, for row 1.*/ private static final int STATE_D_UR_R1 = 1<<2; /** The flag bit for the diagonal down-left significance in the state array, for row 1. */ private static final int STATE_D_DL_R1 = 1<<1; /** The flag bit for the diagonal down-right significance in the state array , for row 1.*/ private static final int STATE_D_DR_R1 = 1; /** The flag bit for the significance in the state array, for row 2. */ private static final int STATE_SIG_R2 = STATE_SIG_R1<<STATE_SEP; /** The flag bit for the "visited" bit in the state array, for row 2. */ private static final int STATE_VISITED_R2 = STATE_VISITED_R1<<STATE_SEP; /** The flag bit for the "not zero context" bit in the state array, for * row 2. This bit is always the OR of bits STATE_H_L_R2, STATE_H_R_R2, * STATE_V_U_R2, STATE_V_D_R2, STATE_D_UL_R2, STATE_D_UR_R2, STATE_D_DL_R2 * and STATE_D_DR_R2. */ private static final int STATE_NZ_CTXT_R2 = STATE_NZ_CTXT_R1<<STATE_SEP; /** The flag bit for the horizontal-left sign in the state array, for row * 2. This bit can only be set if the STATE_H_L_R2 is also set. */ private static final int STATE_H_L_SIGN_R2 = STATE_H_L_SIGN_R1<<STATE_SEP; /** The flag bit for the horizontal-right sign in the state array, for * row 2. This bit can only be set if the STATE_H_R_R2 is also set. */ private static final int STATE_H_R_SIGN_R2 = STATE_H_R_SIGN_R1<<STATE_SEP; /** The flag bit for the vertical-up sign in the state array, for row * 2. This bit can only be set if the STATE_V_U_R2 is also set. */ private static final int STATE_V_U_SIGN_R2 = STATE_V_U_SIGN_R1<<STATE_SEP; /** The flag bit for the vertical-down sign in the state array, for row * 2. This bit can only be set if the STATE_V_D_R2 is also set. */ private static final int STATE_V_D_SIGN_R2 = STATE_V_D_SIGN_R1<<STATE_SEP; /** The flag bit for the previous MR primitive applied in the state array, for row 2. */ private static final int STATE_PREV_MR_R2 = STATE_PREV_MR_R1<<STATE_SEP; /** The flag bit for the horizontal-left significance in the state array, for row 2. */ private static final int STATE_H_L_R2 = STATE_H_L_R1<<STATE_SEP; /** The flag bit for the horizontal-right significance in the state array, for row 2. */ private static final int STATE_H_R_R2 = STATE_H_R_R1<<STATE_SEP; /** The flag bit for the vertical-up significance in the state array, for row 2. */ private static final int STATE_V_U_R2 = STATE_V_U_R1<<STATE_SEP; /** The flag bit for the vertical-down significance in the state array, for row 2. */ private static final int STATE_V_D_R2 = STATE_V_D_R1<<STATE_SEP; /** The flag bit for the diagonal up-left significance in the state array, for row 2. */ private static final int STATE_D_UL_R2 = STATE_D_UL_R1<<STATE_SEP; /** The flag bit for the diagonal up-right significance in the state array, for row 2.*/ private static final int STATE_D_UR_R2 = STATE_D_UR_R1<<STATE_SEP; /** The flag bit for the diagonal down-left significance in the state array, for row 2. */ private static final int STATE_D_DL_R2 = STATE_D_DL_R1<<STATE_SEP; /** The flag bit for the diagonal down-right significance in the state array , for row 2.*/ private static final int STATE_D_DR_R2 = STATE_D_DR_R1<<STATE_SEP; /** The mask to isolate the significance bits for row 1 and 2 of the state * array. */ private static final int SIG_MASK_R1R2 = STATE_SIG_R1|STATE_SIG_R2; /** The mask to isolate the visited bits for row 1 and 2 of the state * array. */ private static final int VSTD_MASK_R1R2 = STATE_VISITED_R1|STATE_VISITED_R2; /** The mask to isolate the bits necessary to identify RLC coding state * (significant, visited and non-zero context, for row 1 and 2). */ private static final int RLC_MASK_R1R2 = STATE_SIG_R1|STATE_SIG_R2| STATE_VISITED_R1|STATE_VISITED_R2| STATE_NZ_CTXT_R1|STATE_NZ_CTXT_R2; /** The mask to obtain the ZC_LUT index from the state information */ // This is needed because of the STATE_V_D_SIGN_R1, STATE_V_U_SIGN_R1, // STATE_H_R_SIGN_R1, and STATE_H_L_SIGN_R1 bits. private static final int ZC_MASK = (1<<8)-1; /** The shift to obtain the SC index to 'SC_LUT' from the state * information, for row 1. */ private static final int SC_SHIFT_R1 = 4; /** The shift to obtain the SC index to 'SC_LUT' from the state * information, for row 2. */ private static final int SC_SHIFT_R2 = SC_SHIFT_R1+STATE_SEP; /** The bit mask to isolate the state bits relative to the sign coding * lookup table ('SC_LUT'). */ private static final int SC_MASK = (1<<SC_LUT_BITS)-1; /** The mask to obtain the MR index to 'MR_LUT' from the 'state' * information. It is to be applied after the 'MR_SHIFT'. */ private static final int MR_MASK = (1<<MR_LUT_BITS)-1; /** The number of bits used to index in the 'fm' lookup table, 7. The 'fs' * table is indexed with one less bit. */ private static final int MSE_LKP_BITS = 7; /** The number of fractional bits used to store data in the 'fm' and 'fs' * lookup tables. */ private static final int MSE_LKP_FRAC_BITS = 13; /** Distortion estimation lookup table for bits coded using the sign-code * (SC) primative, for lossy coding (i.e. normal). */ private static final int FS_LOSSY[] = new int[1<<(MSE_LKP_BITS-1)]; /** Distortion estimation lookup table for bits coded using the * magnitude-refinement (MR) primative, for lossy coding (i.e. normal) */ private static final int FM_LOSSY[] = new int[1<<MSE_LKP_BITS]; /** Distortion estimation lookup table for bits coded using the sign-code * (SC) primative, for lossless coding and last bit-plane. This table is * different from 'fs_lossy' since when doing lossless coding the residual * distortion after the last bit-plane is coded is strictly 0. */ private static final int FS_LOSSLESS[] = new int[1<<(MSE_LKP_BITS-1)]; /** Distortion estimation lookup table for bits coded using the * magnitude-refinement (MR) primative, for lossless coding and last * bit-plane. This table is different from 'fs_lossless' since when doing * lossless coding the residual distortion after the last bit-plane is * coded is strictly 0.*/ private static final int FM_LOSSLESS[] = new int[1<<MSE_LKP_BITS]; /** The buffer for distortion values (avoids reallocation for each code-block), for each thread. */ private double distbufT[][]; /** The buffer for rate values (avoids reallocation for each code-block), for each thread. */ private int ratebufT[][]; /** The buffer for indicating terminated passes (avoids reallocation for * each code-block), for each thread. */ private boolean istermbufT[][]; /** The source code-block to entropy code (avoids reallocation for each code-block), for each thread. */ private CBlkWTData srcblkT[]; /** Buffer for symbols to send to the MQ-coder, for each thread. Used to * reduce the number of calls to the MQ coder. */ // NOTE: The symbol buffer has not prooved to be of any great improvement // in encoding time, but it does not hurt. It's performance should be // better studied under different JVMs. private int symbufT[][]; /** Buffer for the contexts to use when sending buffered symbols to the * MQ-coder, for each thread. Used to reduce the number of calls to the MQ * coder. */ private int ctxtbufT[][]; /** boolean used to signal if the precinct partition is used for * each component and each tile. */ private boolean precinctPartition[][]; /** * Class that takes care of running the 'compressCodeBlock()' method with * thread local arguments. Used only in multithreaded implementation. * */ private class Compressor implements Runnable { /** The index of this compressor. Used to access thread local * variables */ private final int idx; /** The object where to store the compressed code-block */ // Should be private, but some buggy JDK 1.1 compilers complain CBlkRateDistStats ccb; /** The component on which to compress */ // Should be private, but some buggy JDK 1.1 compilers complain int c; /** The options bitmask to use in compression */ // Should be private, but some buggy JDK 1.1 compilers complain int options; /** The reversible flag to use in compression */ // Should be private, but some buggy JDK 1.1 compilers complain boolean rev; /** The length calculation type to use in compression */ // Should be private, but some buggy JDK 1.1 compilers complain int lcType; /** The MQ termination type to use in compression */ // Should be private, but some buggy JDK 1.1 compilers complain int tType; /** The cumulative wall time for this compressor, for each * component. */ private long time[]; /** * Creates a new compressor object with the given index. * * @param idx The index of this compressor. * */ Compressor(int idx) { this.idx = idx; if (DO_TIMING) time = new long[src.getNumComps()]; } /** * Calls the 'compressCodeBlock()' method with thread local * arguments. Once completed it adds itself to the 'completedComps[c]' * stack, where 'c' is the component for which this compressor is * running. This last step occurs even if exceptions are thrown by the * 'compressCodeBlock()' method. * */ public void run() { // Start the code-block compression try { long stime = 0L; if (DO_TIMING) stime = System.currentTimeMillis(); compressCodeBlock(c,ccb,srcblkT[idx],mqT[idx],boutT[idx], outT[idx],stateT[idx],distbufT[idx], ratebufT[idx],istermbufT[idx], symbufT[idx],ctxtbufT[idx],options, rev,lcType,tType); if (DO_TIMING) time[c] += System.currentTimeMillis()-stime; } finally { // Join the queue of completed compression, even if exceptions // occurred. completedComps[c].push(this); } } /** * Returns the wall time spent by this compressor for component 'c' * since the last call to this method (or the creation of this * compressor if not yet called). If DO_TIMING is false 0 is returned. * * @return The wall time in milliseconds spent by this compressor * since the last call to this method. * */ synchronized long getTiming(int c) { if (DO_TIMING) { long t = time[c]; time[c] = 0L; return t; } else { return 0L; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?