public LzxDecoder (int window) { uint wndsize = (uint)(1 << window); int posn_slots; // setup proper exception if(window < 15 || window > 21) throw new UnsupportedWindowSizeRange(); // let's initialise our state m_state = new LzxState(); m_state.actual_size = 0; m_state.window = new byte[wndsize]; for(int i = 0; i < wndsize; i++) m_state.window[i] = 0xDC; m_state.actual_size = wndsize; m_state.window_size = wndsize; m_state.window_posn = 0; /* initialize static tables */ if(extra_bits == null) { extra_bits = new byte[52]; for(int i = 0, j = 0; i <= 50; i += 2) { extra_bits[i] = extra_bits[i+1] = (byte)j; if ((i != 0) && (j < 17)) j++; } } if(position_base == null) { position_base = new uint[51]; for(int i = 0, j = 0; i <= 50; i++) { position_base[i] = (uint)j; j += 1 << extra_bits[i]; } } /* calculate required position slots */ if(window == 20) posn_slots = 42; else if(window == 21) posn_slots = 50; else posn_slots = window << 1; m_state.R0 = m_state.R1 = m_state.R2 = 1; m_state.main_elements = (ushort)(LzxConstants.NUM_CHARS + (posn_slots << 3)); m_state.header_read = 0; m_state.frames_read = 0; m_state.block_remaining = 0; m_state.block_type = LzxConstants.BLOCKTYPE.INVALID; m_state.intel_curpos = 0; m_state.intel_started = 0; // yo dawg i herd u liek arrays so we put arrays in ur arrays so u can array while u array m_state.PRETREE_table = new ushort[(1 << LzxConstants.PRETREE_TABLEBITS) + (LzxConstants.PRETREE_MAXSYMBOLS << 1)]; m_state.PRETREE_len = new byte[LzxConstants.PRETREE_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.MAINTREE_table = new ushort[(1 << LzxConstants.MAINTREE_TABLEBITS) + (LzxConstants.MAINTREE_MAXSYMBOLS << 1)]; m_state.MAINTREE_len = new byte[LzxConstants.MAINTREE_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.LENGTH_table = new ushort[(1 << LzxConstants.LENGTH_TABLEBITS) + (LzxConstants.LENGTH_MAXSYMBOLS << 1)]; m_state.LENGTH_len = new byte[LzxConstants.LENGTH_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.ALIGNED_table = new ushort[(1 << LzxConstants.ALIGNED_TABLEBITS) + (LzxConstants.ALIGNED_MAXSYMBOLS << 1)]; m_state.ALIGNED_len = new byte[LzxConstants.ALIGNED_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; /* initialise tables to 0 (because deltas will be applied to them) */ for(int i = 0; i < LzxConstants.MAINTREE_MAXSYMBOLS; i++) m_state.MAINTREE_len[i] = 0; for(int i = 0; i < LzxConstants.LENGTH_MAXSYMBOLS; i++) m_state.LENGTH_len[i] = 0; }
public LzxDecoder(int window) { uint wndsize = (uint)(1 << window); int posn_slots; // setup proper exception if (window < 15 || window > 21) { throw new UnsupportedWindowSizeRange(); } // let's initialise our state m_state = new LzxState(); m_state.actual_size = 0; m_state.window = new byte[wndsize]; for (int i = 0; i < wndsize; i++) { m_state.window[i] = 0xDC; } m_state.actual_size = wndsize; m_state.window_size = wndsize; m_state.window_posn = 0; /* initialize static tables */ if (extra_bits == null) { extra_bits = new byte[52]; for (int i = 0, j = 0; i <= 50; i += 2) { extra_bits[i] = extra_bits[i + 1] = (byte)j; if ((i != 0) && (j < 17)) { j++; } } } if (position_base == null) { position_base = new uint[51]; for (int i = 0, j = 0; i <= 50; i++) { position_base[i] = (uint)j; j += 1 << extra_bits[i]; } } /* calculate required position slots */ if (window == 20) { posn_slots = 42; } else if (window == 21) { posn_slots = 50; } else { posn_slots = window << 1; } m_state.R0 = m_state.R1 = m_state.R2 = 1; m_state.main_elements = (ushort)(LzxConstants.NUM_CHARS + (posn_slots << 3)); m_state.header_read = 0; m_state.frames_read = 0; m_state.block_remaining = 0; m_state.block_type = LzxConstants.BLOCKTYPE.INVALID; m_state.intel_curpos = 0; m_state.intel_started = 0; // yo dawg i herd u liek arrays so we put arrays in ur arrays so u can array while u array m_state.PRETREE_table = new ushort[(1 << LzxConstants.PRETREE_TABLEBITS) + (LzxConstants.PRETREE_MAXSYMBOLS << 1)]; m_state.PRETREE_len = new byte[LzxConstants.PRETREE_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.MAINTREE_table = new ushort[(1 << LzxConstants.MAINTREE_TABLEBITS) + (LzxConstants.MAINTREE_MAXSYMBOLS << 1)]; m_state.MAINTREE_len = new byte[LzxConstants.MAINTREE_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.LENGTH_table = new ushort[(1 << LzxConstants.LENGTH_TABLEBITS) + (LzxConstants.LENGTH_MAXSYMBOLS << 1)]; m_state.LENGTH_len = new byte[LzxConstants.LENGTH_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.ALIGNED_table = new ushort[(1 << LzxConstants.ALIGNED_TABLEBITS) + (LzxConstants.ALIGNED_MAXSYMBOLS << 1)]; m_state.ALIGNED_len = new byte[LzxConstants.ALIGNED_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; /* initialise tables to 0 (because deltas will be applied to them) */ for (int i = 0; i < LzxConstants.MAINTREE_MAXSYMBOLS; i++) { m_state.MAINTREE_len[i] = 0; } for (int i = 0; i < LzxConstants.LENGTH_MAXSYMBOLS; i++) { m_state.LENGTH_len[i] = 0; } }
public LzxDecoder(int windowSize, int maxDataBlockSize) { /* make sure window size is power of 2 */ int window_mask = windowSize - 1; if ((windowSize & window_mask) != 0) { throw new LzxInvalidWindowSize(); } int window_bits = 0; int window_test = windowSize >> 1; while (window_test != 0) { window_bits++; window_test = window_test >> 1; } /* LZX supports window sizes of 2^15 (32Kb) through 2^21 (2Mb) */ if (window_bits < 15 || window_bits > 21) { throw new LzxInvalidWindowSize(); } // Note down our agreed upon size this.maxDataBlockSize = maxDataBlockSize; this.minBlockSize = maxDataBlockSize + LzxConstants.MAX_GROWTH; // let's initialise our state m_state = new LzxState(); m_state.actual_size = 0; m_state.window = new byte[windowSize]; m_state.actual_size = (uint)windowSize; m_state.window_size = (uint)windowSize; m_state.window_posn = 0; /* initialize static tables */ if (extra_bits == null) { extra_bits = new byte[52]; for (int i = 0, j = 0; i <= 50; i += 2) { extra_bits[i] = extra_bits[i + 1] = (byte)j; if ((i != 0) && (j < 17)) { j++; } } } if (position_base == null) { position_base = new uint[51]; for (int i = 0, j = 0; i <= 50; i++) { position_base[i] = (uint)j; j += 1 << extra_bits[i]; } } /* calculate required position slots */ int posn_slots = window_bits << 1; if (window_bits == 20) { posn_slots = 42; } else if (window_bits == 21) { posn_slots = 50; } m_state.R0 = m_state.R1 = m_state.R2 = 1; m_state.main_elements = (ushort)(LzxConstants.NUM_CHARS + (posn_slots << 3)); m_state.header_read = 0; m_state.frames_read = 0; m_state.block_remaining = 0; m_state.block_type = LzxConstants.BLOCKTYPE.INVALID; m_state.intel_curpos = 0; m_state.intel_started = 0; // yo dawg i herd u liek arrays so we put arrays in ur arrays so u can array while u array m_state.PRETREE_table = new ushort[(1 << LzxConstants.PRETREE_TABLEBITS) + (LzxConstants.PRETREE_MAXSYMBOLS << 1)]; m_state.PRETREE_len = new byte[LzxConstants.PRETREE_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.MAINTREE_table = new ushort[(1 << LzxConstants.MAINTREE_TABLEBITS) + (LzxConstants.MAINTREE_MAXSYMBOLS << 1)]; m_state.MAINTREE_len = new byte[LzxConstants.MAINTREE_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.LENGTH_table = new ushort[(1 << LzxConstants.LENGTH_TABLEBITS) + (LzxConstants.LENGTH_MAXSYMBOLS << 1)]; m_state.LENGTH_len = new byte[LzxConstants.LENGTH_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; m_state.ALIGNED_table = new ushort[(1 << LzxConstants.ALIGNED_TABLEBITS) + (LzxConstants.ALIGNED_MAXSYMBOLS << 1)]; m_state.ALIGNED_len = new byte[LzxConstants.ALIGNED_MAXSYMBOLS + LzxConstants.LENTABLE_SAFETY]; /* initialise tables to 0 (because deltas will be applied to them) */ for (int i = 0; i < LzxConstants.MAINTREE_MAXSYMBOLS; i++) { m_state.MAINTREE_len[i] = 0; } for (int i = 0; i < LzxConstants.LENGTH_MAXSYMBOLS; i++) { m_state.LENGTH_len[i] = 0; } }