byte[] UnpackLze(Stream input, uint unpacked_size) { var data = new byte[unpacked_size]; var header = new byte[4]; int dst = 0; using (var bits = new MsbBitStream(input, true)) { while (dst < data.Length) { if (4 != input.Read(header, 0, 4)) { break; } if (!Binary.AsciiEqual(header, "ze")) { throw new InvalidFormatException("Malformed compressed stream"); } int chunk_length = BigEndian.ToUInt16(header, 2); bits.Reset(); UnpackZeChunk(bits, data, dst, chunk_length); dst += chunk_length; } return(data); } }
public void Unpack() { if (8 == m_info.BPP) { m_input.Position = m_info.PaletteOffset; Palette = ImageFormat.ReadPalette(m_input.AsStream); } m_bits.Input.Position = m_info.DataOffset; ResetDict(); UnpackChannel(0); if (m_pixel_size > 1) { UnpackChannel(1); UnpackChannel(2); } if (m_info.AlphaOffset != 0) { ConvertToBgr32(); try { m_bits.Input.Position = m_info.AlphaOffset; m_bits.Reset(); ResetDict(); UnpackChannel(3); } catch { Format = PixelFormats.Bgr32; } } }
public List <SwfChunk> Parse() { ReadDimensions(); m_bits.Reset(); m_frame_rate = m_input.ReadUInt16(); m_frame_count = m_input.ReadUInt16(); for (;;) { var chunk = ReadChunk(); if (null == chunk) { break; } m_chunks.Add(chunk); } return(m_chunks); }
bool DecodeStream(uint data_pos, uint index_size) { ReadIndex(index_size); m_input.Position = data_pos; m_bits.Reset(); bool small_index = index_size < 0x1002; m_index_length_limit = small_index ? 6 : 14; int index_bit_length = small_index ? 3 : 4; while (m_dst_size > 0) { int dst_count = 1; int index_length = m_bits.GetBits(index_bit_length); if (0 == index_length) { dst_count = m_bits.GetBits(4) + 2; index_length = m_bits.GetBits(index_bit_length); } if (0 == index_length) { return(false); } int index = GetIndex(index_length); if (index >= index_size) { return(false); } if (dst_count > m_dst_size) { return(false); } m_dst_size -= dst_count; ushort word = m_index[index]; do { LittleEndian.Pack(word, m_data, edi); edi += 4; } while (0 != --dst_count); } return(true); }
/* * public void Decode (Stream output) * { * int block_align = (int)m_format.BlockAlign; * var frame = new short[m_samples_per_frame * Format.Channels]; * int sample = 0; * while (sample < SampleCount) * { * int channel_offset = 0; * for (int i = 0; i < m_format.Channels; ++i) * { * DecodeFrame (i, frame); * } * int samples_in_frame = Math.Min (SampleCount - sample, m_samples_per_frame); * output.Write (frame, 0, samples_in_frame * block_align); // XXX convert to byte array * sample += samples_in_frame; * } * } */ public void SetPosition(long position) { m_input.Input.Position = position; m_input.Reset(); }