📄 stdentropycoder.java
字号:
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 MR_LUT[0] = 16; // One or more significant, prev MR off for (i=1; i<(1<<(MR_LUT_BITS-1)); i++) { MR_LUT[i] = 17; } // Previous MR on, significance irrelevant for (; i<(1<<MR_LUT_BITS); i++) { MR_LUT[i] = 18; } // Initialize the distortion estimation lookup tables // fs tables for (i=0; i<(1<<(MSE_LKP_BITS-1)); i++) { // In fs we index by val-1, since val is really: 1 <= val < 2 val = (double)i / (1<<(MSE_LKP_BITS-1)) + 1.0; deltaMSE = val*val; FS_LOSSLESS[i] = (int) Math.floor(deltaMSE * ((double)(1<<MSE_LKP_FRAC_BITS)) + 0.5); val -= 1.5; deltaMSE -= val*val; FS_LOSSY[i] = (int) Math.floor(deltaMSE * ((double)(1<<MSE_LKP_FRAC_BITS)) + 0.5); } // fm tables for (i=0; i<(1<<MSE_LKP_BITS); i++) { val = (double)i / (1<<(MSE_LKP_BITS-1)); deltaMSE = (val-1.0)*(val-1.0); FM_LOSSLESS[i] = (int) Math.floor(deltaMSE * ((double)(1<<MSE_LKP_FRAC_BITS)) + 0.5); val -= (i<(1<<(MSE_LKP_BITS-1))) ? 0.5 : 1.5; deltaMSE -= val*val; FM_LOSSY[i] = (int) Math.floor(deltaMSE * ((double)(1<<MSE_LKP_FRAC_BITS)) + 0.5); } } /** * Instantiates a new entropy coder engine, with the specified source of * data, nominal block width and height. * * <P>If the 'OPT_ER_TERM' option is given then the MQ termination must be * 'TERM_PRED_ER' or an exception is thrown. * * @param src The source of data * * @param encSpec The encoder specifications * * @see MQCoder * */ public StdEntropyCoder(CBlkQuantDataSrcEnc src, EncoderSpecs encSpec) { super(src); this.encSpec = encSpec; int maxCBlkWidth, maxCBlkHeight; int i; // Counter int nt; // The number of threads int tsl; // Size for thread structures // Get the biggest width/height for the code-blocks maxCBlkWidth = encSpec.cblks.getMaxCBlkWidth(); maxCBlkHeight = encSpec.cblks.getMaxCBlkHeight(); // Get the number of threads to use, or default to one try { nt = Integer.parseInt(System.getProperty(THREADS_PROP_NAME, DEF_THREADS_NUM)); if (nt < 0) throw new NumberFormatException(); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid number of threads "+ "for "+ "entropy coding in property "+ THREADS_PROP_NAME); } // If we do timing create necessary structures if (DO_TIMING) { time = new long[src.getNumComps()]; // If we are timing make sure that 'finalize' gets called. System.runFinalizersOnExit(true); } // If using multithreaded implementation get necessasry objects if (nt > 0) { FacilityManager.getMsgLogger(). printmsg(MsgLogger.INFO, "Using multithreaded entropy coder "+ "with "+nt+" compressor threads."); tsl = nt; tPool = new ThreadPool(nt,Thread.currentThread().getPriority()+ THREADS_PRIORITY_INC,"StdEntropyCoder"); idleComps = new Stack(); completedComps = new Stack[src.getNumComps()]; nBusyComps = new int[src.getNumComps()]; finishedTileComponent = new boolean[src.getNumComps()]; for (i=src.getNumComps()-1; i>=0; i--) { completedComps[i] = new Stack(); } for (i=0; i<nt; i++) { idleComps.push(new StdEntropyCoder.Compressor(i)); } } else { tsl = 1; tPool = null; idleComps = null; completedComps = null; nBusyComps = null; finishedTileComponent = null; } // Allocate data structures outT = new ByteOutputBuffer[tsl]; mqT = new MQCoder[tsl]; boutT = new BitToByteOutput[tsl]; stateT = new int[tsl][(maxCBlkWidth+2)*((maxCBlkHeight+1)/2+2)];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -