📄 stdentropydecoder.java
字号:
/* * CVS identifier: * * $Id: StdEntropyDecoder.java,v 1.26 2001/02/14 10:48:15 grosbois Exp $ * * Class: StdEntropyDecoder * * Description: Entropy decoding engine of stripes in code-blocks * * * * COPYRIGHT: * * This software module was originally developed by Rapha雔 Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askel鰂 (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, F閘ix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. * * Copyright (c) 1999/2000 JJ2000 Partners. * */package jj2000.j2k.entropy.decoder;import jj2000.j2k.wavelet.synthesis.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.entropy.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import jj2000.j2k.*;/** * This class implements the JPEG 2000 entropy decoder, which codes stripes in * code-blocks. This entropy decoding engine decodes one code-block at a time. * * The code-block are rectangular, with dimensions which must be powers of * 2. Each dimension has to be no smaller than 4 and no larger than 256. The * product of the two dimensions (i.e. area of the code-block) may not exceed * 4096. * * Context 0 of the MQ-coder is used as the uniform one (uniform, non-adaptive * probability distribution). Context 1 is used for RLC coding. Contexts 2-10 * are used for zero-coding (ZC), contexts 11-15 are used for sign-coding (SC) * and contexts 16-18 are used for magnitude-refinement (MR). * * <P>This implementation also provides some timing features. They can be * enabled by setting the 'DO_TIMING' constant of this class to true and * recompiling. The timing uses the 'System.currentTimeMillis()' Java API * call, which returns wall clock time, not the actual CPU time used. The * timing results will be printed on the message output. Since the times * reported are wall clock times and not CPU usage times they can not be added * to find the total used time (i.e. some time might be counted in several * places). When timing is disabled ('DO_TIMING' is false) there is no penalty * if the compiler performs some basic optimizations. Even if not the penalty * should be negligeable. * */public class StdEntropyDecoder extends EntropyDecoder implements StdEntropyCoderOptions { /** Whether to collect timing information or not: false. Used as a compile * time directive. */ private final static boolean DO_TIMING = false; /** The cumulative wall time for the entropy coding engine, for each * component. */ private long time[]; /** The bit based input for arithmetic coding bypass (i.e. raw) coding */ private ByteToBitInput bin; /** The MQ decoder to use. It has in as the underlying source of coded * data. */ private MQDecoder mq; /** The decoder spec */ private DecoderSpecs decSpec; /** The options that are turned on, as flag bits. The options are * 'OPT_REG_TERM', 'OPT_RESET_MQ', 'OPT_VERT_STR_CAUSAL', 'OPT_BYPASS' and * 'OPT_SEG_MARKERS' as defined in the StdEntropyCoderOptions interface * * @see StdEntropyCoderOptions **/ private int options; /** Flag to indicate if we should try to detect errors or just ignore any * error resilient information */ private final boolean doer; /** Flag to indicate if we should be verbose about bit stream errors detected with the error resilience options */ private final boolean verber; /** Number of bits used for the Zero Coding lookup table */ private static final int ZC_LUT_BITS = 8; /** Zero Coding context lookup tables for the LH global orientation */ private static final int ZC_LUT_LH[] = new int[1<<ZC_LUT_BITS]; /** Zero Coding context lookup tables for the HL global orientation */ private static final int ZC_LUT_HL[] = new int[1<<ZC_LUT_BITS]; /** Zero Coding context lookup tables for the HH global orientation */ private static final int ZC_LUT_HH[] = new int[1<<ZC_LUT_BITS]; /** Number of bits used for the Sign Coding lookup table */ private static final int SC_LUT_BITS = 9; /** Sign Coding context lookup table. The index into the table is a 9 bit * index, which correspond the the value in the 'state' array shifted by * 'SC_SHIFT'. Bits 8-5 are the signs of the horizontal-left, * horizontal-right, vertical-up and vertical-down neighbors, * respectively. Bit 4 is not used (0 or 1 makes no difference). Bits 3-0 * are the significance of the horizontal-left, horizontal-right, * vertical-up and vertical-down neighbors, respectively. The least 4 bits * of the value in the lookup table define the context number and the sign * bit defines the "sign predictor". */ private static final int SC_LUT[] = new int[1<<SC_LUT_BITS]; /** The mask to obtain the context index from the 'SC_LUT' */ private static final int SC_LUT_MASK = (1<<4)-1; /** The shift to obtain the sign predictor from the 'SC_LUT'. It must be * an unsigned shift. */ private static final int SC_SPRED_SHIFT = 31; /** The sign bit for int data */ private static final int INT_SIGN_BIT = 1<<31; /** The number of bits used for the Magnitude Refinement lookup table */ private static final int MR_LUT_BITS = 9; /** Magnitude Refinement context lookup table */ private static final int MR_LUT[] = new int[1<<MR_LUT_BITS]; /** The number of contexts used */ private static final int NUM_CTXTS = 19; /** The RLC context */ private static final int RLC_CTXT = 1; /** The UNIFORM context (with a uniform probability distribution which * does not adapt) */ private static final int UNIF_CTXT = 0; /** The initial states for the MQ coder */ private static final int MQ_INIT[] = {46, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /** The 4 symbol segmentation marker (decimal 10, which is binary sequence 1010) */ private static final int SEG_MARKER = 10; /** * The state array for entropy coding. Each element of the state array * stores the state of two coefficients. The lower 16 bits store the state * of a coefficient in row 'i' and column 'j', while the upper 16 bits * store the state of a coefficient in row 'i+1' and column 'j'. The 'i' * row is either the first or the third row of a stripe. This packing of * the states into 32 bit words allows a faster scan of all coefficients * on each coding pass and diminished the amount of data transferred. The * size of the state array is increased by 1 on each side (top, bottom, * left, right) to handle boundary conditions without any special logic. * * <P>The state of a coefficient is stored in the following way in the * lower 16 bits, where bit 0 is the least significant bit. Bit 15 is the * significance of a coefficient (0 if non-significant, 1 otherwise). Bit * 14 is the visited state (i.e. if a coefficient has been coded in the * significance propagation pass of the current bit-plane). Bit 13 is the * "non zero-context" state (i.e. if one of the eight immediate neighbors * is significant it is 1, otherwise is 0). Bits 12 to 9 store the sign of * the already significant left, right, up and down neighbors (1 for * negative, 0 for positive or not yet significant). Bit 8 indicates if * the magnitude refinement has already been applied to the * coefficient. Bits 7 to 4 store the significance of the left, right, up * and down neighbors (1 for significant, 0 for non significant). Bits 3 * to 0 store the significance of the diagonal coefficients (up-left, * up-right, down-left and down-right; 1 for significant, 0 for non * significant). * * <P>The upper 16 bits the state is stored as in the lower 16 bits, * but with the bits shifted up by 16. * * <P>The lower 16 bits are referred to as "row 1" ("R1") while the upper * 16 bits are referred to as "row 2" ("R2"). * */ private final int state[]; /** The separation between the upper and lower bits in the state array: 16 * */ private static final int STATE_SEP = 16; /** The flag bit for the significance in the state array, for row 1. */ 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -