public override Stream OpenEntry(ArcFile arc, Entry entry) { if (entry.Size <= 8 || !entry.Name.EndsWith (".snc", StringComparison.InvariantCultureIgnoreCase) || !arc.File.View.AsciiEqual (entry.Offset, "CMP_")) return arc.File.CreateStream (entry.Offset, entry.Size); int unpacked_size = arc.File.View.ReadInt32 (entry.Offset+4); using (var input = arc.File.CreateStream (entry.Offset+8, entry.Size-8)) using (var lzss = new LzssReader (input, (int)(entry.Size - 8), unpacked_size)) { lzss.FrameFill = 0x20; lzss.Unpack(); return new MemoryStream (lzss.Data); } }
public override ImageData Read(Stream stream, ImageMetaData info) { var meta = (GrMetaData)info; using (var reader = new LzssReader (stream, (int)stream.Length, meta.UnpackedSize+2)) { reader.Unpack(); if (32 != info.BPP) using (var bmp = new MemoryStream (reader.Data)) return base.Read (bmp, info); int stride = (int)info.Width*4; var pixels = new byte[stride*info.Height]; int dst = 0; int offset = 0x36; for (int src = stride*((int)info.Height-1); src >= 0; src -= stride) { Buffer.BlockCopy (reader.Data, offset+src, pixels, dst, stride); dst += stride; } return ImageData.Create (info, PixelFormats.Bgra32, null, pixels); } }
public override Stream OpenEntry(ArcFile arc, Entry entry) { if (0 == entry.Size) return Stream.Null; var larc = arc as LuciArchive; var lent = entry as LuciEntry; Stream input = arc.File.CreateStream (entry.Offset, entry.Size); if (null == larc || null == lent) return input; byte[] data; using (input) { if (lent.IsPacked) { using (var reader = new LzssReader (input, (int)lent.Size, (int)lent.UnpackedSize)) { reader.Unpack(); data = reader.Data; } } else { data = new byte[lent.Size]; input.Read (data, 0, data.Length); } } if (larc.Info.WholeCrypt) { DecryptContent (data, larc.Scheme.ContentXor); } if (larc.Info.IsEncrypted) { int count = Math.Min (data.Length, 0x100); if (count != 0) DecryptEntry (data, count, larc.Info.Key, larc.Scheme.RotatePattern); } input = new MemoryStream (data); if (null != larc.Info.Prefix) return new PrefixStream (larc.Info.Prefix, input); else return input; }
static byte[] DecodeListBin(byte[] data) { var header = new byte[0x30]; DecodeDPD (data, 0, 0x30, header); int packed_size = LittleEndian.ToInt32 (header, 0x0C); int unpacked_size = LittleEndian.ToInt32 (header, 0x10); if (packed_size <= 0 || packed_size > data.Length-0x30) return null; if (Binary.AsciiEqual (header, 0, "DPDC")) { var decrypted = new byte[packed_size]; DecodeDPD (data, 0x30, packed_size, decrypted); return decrypted; } if (Binary.AsciiEqual (header, 0, "SZLC")) // LZSS { using (var input = new MemoryStream (data, 0x30, packed_size)) using (var lzss = new LzssReader (input, packed_size, unpacked_size)) { lzss.Unpack(); return lzss.Data; } } if (Binary.AsciiEqual (header, 0, "ELRC")) // RLE { var unpacked = new byte[unpacked_size]; int min_repeat = LittleEndian.ToInt32 (header, 0x1C); DecodeRLE (data, 0x30, packed_size, unpacked, min_repeat); return unpacked; } return null; }
public override ImageMetaData ReadMetaData(Stream stream) { using (var reader = new LzssReader (stream, (int)stream.Length, 0x26)) // BMP header { reader.Unpack(); var bmp = reader.Data; if (bmp[0] != 'B' || bmp[1] != 'M') return null; int file_size = LittleEndian.ToInt32 (bmp, 2); int width = LittleEndian.ToInt32 (bmp, 0x12); int height = LittleEndian.ToInt32 (bmp, 0x16); int bpp = LittleEndian.ToInt16 (bmp, 0x1c); int image_size = LittleEndian.ToInt32 (bmp, 0x22); if (0 == image_size) image_size = width * height * (bpp / 8); return new GrMetaData { Width = (uint)width, Height = (uint)height, BPP = bpp, UnpackedSize = 24 == bpp ? file_size : (image_size+0x36), }; } }
public override ImageData Read(Stream file, ImageMetaData info) { var meta = (GgdMetaData)info; file.Position = meta.HeaderSize + 4; var palette_data = new byte[0x400]; if (palette_data.Length != file.Read (palette_data, 0, palette_data.Length)) throw new InvalidFormatException(); var colors = new Color[256]; for (int i = 0; i < 256; ++i) { colors[i] = Color.FromRgb (palette_data[i*4+2], palette_data[i*4+1], palette_data[i*4]); } file.Seek (4, SeekOrigin.Current); int input_size = (int)(file.Length - file.Position); using (var reader = new LzssReader (file, input_size, (int)meta.BitmapSize)) { reader.Unpack(); var palette = new BitmapPalette (colors); int stride = ((int)meta.Width + 3) & ~3; return ImageData.Create (info, PixelFormats.Indexed8, palette, reader.Data, stride); } }
// DOUBLE private ImageData ReadV2() { if (0 != m_info.PackedSize) { using (var reader = new LzssReader (m_input, m_info.PackedSize, m_info.UnpackedSize)) { reader.Unpack(); m_image_data = reader.Data; } } else { m_image_data = new byte[m_info.UnpackedSize]; if (m_image_data.Length != m_input.Read (m_image_data, 0, m_image_data.Length)) throw new InvalidFormatException ("Unexpected end of file"); } int pixels_offset = 0; if (8 == m_info.BPP) { SetPalette (m_image_data); pixels_offset += 0x400; } if (0 == pixels_offset) return ImageData.Create (m_info, Format, Palette, m_image_data); if (pixels_offset + m_stride*(int)m_info.Height > m_image_data.Length) throw new InvalidFormatException(); unsafe { fixed (byte* pixels = &m_image_data[pixels_offset]) { var bitmap = BitmapSource.Create ((int)m_info.Width, (int)m_info.Height, ImageData.DefaultDpiX, ImageData.DefaultDpiY, Format, Palette, (IntPtr)pixels, m_image_data.Length-pixels_offset, m_stride); bitmap.Freeze(); return new ImageData (bitmap, m_info); } } }
private ImageData ReadV1() { if (8 == m_info.BPP) { var palette_data = new byte[0x400]; if (palette_data.Length != m_input.Read (palette_data, 0, palette_data.Length)) throw new InvalidFormatException ("Unexpected end of file"); SetPalette (palette_data); } var packed = new byte[m_info.PackedSize]; if (packed.Length != m_input.Read (packed, 0, packed.Length)) throw new InvalidFormatException ("Unexpected end of file"); for (int i = 0; i < packed.Length; ++i) packed[i] ^= (byte)i; using (var input = new MemoryStream (packed)) using (var reader = new LzssReader (input, packed.Length, m_info.UnpackedSize)) { reader.Unpack(); m_image_data = new byte[m_info.UnpackedSize]; // flip pixels vertically int dst = 0; for (int src = m_stride * ((int)m_info.Height-1); src >= 0; src -= m_stride) { Buffer.BlockCopy (reader.Data, src, m_image_data, dst, m_stride); dst += m_stride; } } return ImageData.Create (m_info, Format, Palette, m_image_data); }