⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdentropydecoder.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
   /** 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, STATE_V_U_SIGN,    // STATE_H_R_SIGN, and STATE_H_L_SIGN 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<<9)-1;    /** The source code-block to entropy code (avoids reallocation for each        code-block). */    private DecLyrdCBlk srcblk;    /** Static initializer: initializes all the lookup tables. */    static {        int i,j;        double val, deltaMSE;        int inter_sc_lut[];        int ds,us,rs,ls;        int dsgn,usgn,rsgn,lsgn;        int h,v;        // Initialize the zero coding lookup tables        // LH        // - No neighbors significant        ZC_LUT_LH[0] = 2;        // - No horizontal or vertical neighbors significant        for (i=1; i<16; i++) { // Two or more diagonal coeffs significant            ZC_LUT_LH[i] = 4;        }        for (i=0; i<4; i++) { // Only one diagonal coeff significant            ZC_LUT_LH[1<<i] = 3;        }        // - No horizontal neighbors significant, diagonal irrelevant        for (i=0; i<16; i++) {            // Only one vertical coeff significant            ZC_LUT_LH[STATE_V_U_R1 | i] = 5;            ZC_LUT_LH[STATE_V_D_R1 | i] = 5;            // The two vertical coeffs significant            ZC_LUT_LH[STATE_V_U_R1 | STATE_V_D_R1 | i] = 6;        }        // - One horiz. neighbor significant, diagonal/vertical non-significant        ZC_LUT_LH[STATE_H_L_R1] = 7;        ZC_LUT_LH[STATE_H_R_R1] = 7;        // - One horiz. significant, no vertical significant, one or more        // diagonal significant        for (i=1; i<16; i++) {            ZC_LUT_LH[STATE_H_L_R1 | i] = 8;            ZC_LUT_LH[STATE_H_R_R1 | i] = 8;        }        // - One horiz. significant, one or more vertical significant,        // diagonal irrelevant        for (i=1; i<4; i++) {            for (j=0; j<16; j++) {                ZC_LUT_LH[STATE_H_L_R1 | (i<<4) | j] = 9;                ZC_LUT_LH[STATE_H_R_R1 | (i<<4) | j] = 9;            }        }        // - Two horiz. significant, others irrelevant        for (i=0; i<64; i++) {            ZC_LUT_LH[STATE_H_L_R1 | STATE_H_R_R1 | i] = 10;        }                // HL                // - No neighbors significant        ZC_LUT_HL[0] = 2;        // - No horizontal or vertical neighbors significant        for (i=1; i<16; i++) { // Two or more diagonal coeffs significant            ZC_LUT_HL[i] = 4;        }        for (i=0; i<4; i++) { // Only one diagonal coeff significant            ZC_LUT_HL[1<<i] = 3;        }        // - No vertical significant, diagonal irrelevant        for (i=0; i<16; i++) {            // One horiz. significant            ZC_LUT_HL[STATE_H_L_R1 | i] = 5;            ZC_LUT_HL[STATE_H_R_R1 | i] = 5;            // Two horiz. significant            ZC_LUT_HL[STATE_H_L_R1 | STATE_H_R_R1 | i] = 6;        }        // - One vert. significant, diagonal/horizontal non-significant        ZC_LUT_HL[STATE_V_U_R1] = 7;        ZC_LUT_HL[STATE_V_D_R1] = 7;        // - One vert. significant, horizontal non-significant, one or more        // diag. significant        for (i=1; i<16; i++) {            ZC_LUT_HL[STATE_V_U_R1 | i] = 8;            ZC_LUT_HL[STATE_V_D_R1 | i] = 8;        }        // - One vertical significant, one or more horizontal significant,        // diagonal irrelevant        for (i=1; i<4; i++) {            for (j=0; j<16; j++) {                ZC_LUT_HL[(i<<6) | STATE_V_U_R1 | j] = 9;                ZC_LUT_HL[(i<<6) | STATE_V_D_R1 | j] = 9;            }        }        // - Two vertical significant, others irrelevant        for (i=0; i<4; i++) {            for (j=0; j<16; j++) {                ZC_LUT_HL[(i<<6) | STATE_V_U_R1 | STATE_V_D_R1 | j] = 10;            }        }        // HH        int[] twoBits = {3,5,6,9,10,12}; // Figures (between 0 and 15)        // countaning 2 and only 2 bits on in its binary representation.        int[] oneBit  = {1,2,4,8}; // Figures (between 0 and 15)        // countaning 1 and only 1 bit on in its binary representation.        int[] twoLeast = {3,5,6,7,9,10,11,12,13,14,15}; // Figures        // (between 0 and 15) countaining, at least, 2 bits on in its        // binary representation.         int[] threeLeast = {7,11,13,14,15}; // Figures        // (between 0 and 15) countaining, at least, 3 bits on in its        // binary representation.        // - None significant        ZC_LUT_HH[0] = 2;        // - One horizontal+vertical significant, none diagonal        for(i=0; i<oneBit.length; i++)            ZC_LUT_HH[ oneBit[i]<<4 ] = 3;        // - Two or more horizontal+vertical significant, diagonal non-signif        for(i=0; i<twoLeast.length; i++)            ZC_LUT_HH[ twoLeast[i]<<4 ] = 4;        // - One diagonal significant, horiz./vert. non-significant        for(i=0; i<oneBit.length; i++)            ZC_LUT_HH[ oneBit[i] ] = 5;                // - One diagonal significant, one horiz.+vert. significant        for(i=0; i<oneBit.length; i++)            for(j=0; j<oneBit.length; j++)                ZC_LUT_HH[ (oneBit[i]<<4) | oneBit[j] ] = 6;        // - One diag signif, two or more horiz+vert signif        for(i=0; i<twoLeast.length; i++)            for(j=0; j<oneBit.length; j++)                ZC_LUT_HH[ (twoLeast[i]<<4) | oneBit[j] ] = 7;        // - Two diagonal significant, none horiz+vert significant        for(i=0; i<twoBits.length; i++)            ZC_LUT_HH[ twoBits[i] ] = 8;        // - Two diagonal significant, one or more horiz+vert significant        for(j=0; j<twoBits.length; j++)            for(i=1; i<16; i++)                ZC_LUT_HH[ (i<<4) | twoBits[j] ] = 9;        // - Three or more diagonal significant, horiz+vert irrelevant        for(i=0; i<16; i++)            for(j=0; j<threeLeast.length; j++)                ZC_LUT_HH[ (i<<4) | threeLeast[j] ] = 10;        // Initialize the SC lookup tables        // Use an intermediate sign code lookup table that is similar to the        // one in the VM text, in that it depends on the 'h' and 'v'        // quantities. The index into this table is a 6 bit index, the top 3        // bits are (h+1) and the low 3 bits (v+1).        inter_sc_lut = new int[36];        inter_sc_lut[(2<<3)|2] = 15;        inter_sc_lut[(2<<3)|1] = 14;        inter_sc_lut[(2<<3)|0] = 13;        inter_sc_lut[(1<<3)|2] = 12;        inter_sc_lut[(1<<3)|1] = 11;        inter_sc_lut[(1<<3)|0] = 12 | INT_SIGN_BIT;        inter_sc_lut[(0<<3)|2] = 13 | INT_SIGN_BIT;        inter_sc_lut[(0<<3)|1] = 14 | INT_SIGN_BIT;        inter_sc_lut[(0<<3)|0] = 15 | INT_SIGN_BIT;        // Using the intermediate sign code lookup table create the final        // one. The index into this table is a 9 bit index, the low 4 bits are         // the significance of the 4 horizontal/vertical neighbors, while the        // top 4 bits are the signs of those neighbors. The bit in the middle        // is ignored. This index arrangement matches the state bits in the        // 'state' array, thus direct addressing of the table can be done from         // the sate information.        for (i=0; i<(1<<SC_LUT_BITS)-1; i++) {            ds = i & 0x01;        // significance of down neighbor            us = (i >> 1) & 0x01; // significance of up neighbor            rs = (i >> 2) & 0x01; // significance of right neighbor            ls = (i >> 3) & 0x01; // significance of left neighbor            dsgn = (i >> 5) & 0x01; // sign of down neighbor            usgn = (i >> 6) & 0x01; // sign of up neighbor            rsgn = (i >> 7) & 0x01; // sign of right neighbor            lsgn = (i >> 8) & 0x01; // sign of left neighbor            // Calculate 'h' and 'v' as in VM text            h = ls*(1-2*lsgn)+rs*(1-2*rsgn);            h = (h >= -1) ? h : -1;            h = (h <= 1) ? h : 1;            v = us*(1-2*usgn)+ds*(1-2*dsgn);            v = (v >= -1) ? v : -1;            v = (v <= 1) ? v : 1;            // Get context and sign predictor from 'inter_sc_lut'            SC_LUT[i] = inter_sc_lut[(h+1)<<3|(v+1)];        }        inter_sc_lut = null;        // Initialize the MR lookup tables        // None significant, prev MR off

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -