} // 'YGP' public override ImageMetaData ReadMetaData(Stream stream) { stream.Position = 4; using (var reader = new ArcView.Reader(stream)) { int mask_pos = reader.ReadUInt16(); // 04 byte type = reader.ReadByte(); // 06 if (type != 1 && type != 2) { return(null); } var info = new YgpMetaData { Type = type, BPP = 32 }; info.Flags = reader.ReadByte(); // 07 int header_size = reader.ReadInt32(); // 08 stream.Position = header_size; info.DataSize = reader.ReadInt32(); // XX+00 info.Width = reader.ReadUInt16(); // XX+04 info.Height = reader.ReadUInt16(); // XX+06 info.DataOffset = header_size + 8; if (0 != (info.Flags & 4)) { stream.Position = 0x14; info.OffsetX = reader.ReadInt16(); info.OffsetY = reader.ReadInt16(); } return(info); } }
} // 'CWDP' public override ImageMetaData ReadMetaData(Stream stream) { using (var input = new ArcView.Reader(stream)) { input.ReadInt32(); uint width = Binary.BigEndian(input.ReadUInt32()); uint height = Binary.BigEndian(input.ReadUInt32()); if (0 == width || 0 == height) { return(null); } int bpp = input.ReadByte(); int color_type = input.ReadByte(); switch (color_type) { case 2: bpp *= 3; break; case 4: bpp *= 2; break; case 6: bpp *= 4; break; case 3: case 0: break; default: return(null); } return(new ImageMetaData { Width = width, Height = height, BPP = bpp, }); } }
public override ImageMetaData ReadMetaData(Stream stream) { stream.Seek(3, SeekOrigin.Current); using (var input = new ArcView.Reader(stream)) { int bpp = input.ReadByte(); int x = 0; int y = 0; int type = bpp; int header_size = 8; if (2 == type) { bpp = input.ReadByte(); header_size = 13; } else if (1 == type) { bpp = input.ReadByte(); x = input.ReadInt16(); y = input.ReadInt16(); header_size = 13; } else { type = 0; } if (8 != bpp && 24 != bpp && 32 != bpp) { return(null); } uint w = input.ReadUInt16(); uint h = input.ReadUInt16(); if (2 == type) { x = input.ReadInt16(); y = input.ReadInt16(); } return(new ElgMetaData { Width = w, Height = h, OffsetX = x, OffsetY = y, BPP = bpp, Type = type, HeaderSize = header_size, }); } }
public override ImageMetaData ReadMetaData(Stream stream) { using (var file = new ArcView.Reader(stream)) { stream.Seek(3, SeekOrigin.Current); byte id = file.ReadByte(); uint data_size = file.ReadUInt32(); uint width = file.ReadUInt32(); uint height = file.ReadUInt32(); uint stride = file.ReadUInt32(); if (stride < width) { throw new NotSupportedException(); } if (stride * height != data_size) { return(null); } return(new MfgMetaData { Width = width, Height = height, BPP = (int)(stride * 8 / width), Type = id, Stride = (int)stride, }); } }
public override ImageMetaData ReadMetaData(Stream stream) { stream.Position = 4; using (var reader = new ArcView.Reader (stream)) { int mask_pos = reader.ReadUInt16(); // 04 byte type = reader.ReadByte(); // 06 if (type != 1 && type != 2) return null; var info = new YgpMetaData { Type = type, BPP = 32 }; info.Flags = reader.ReadByte(); // 07 int header_size = reader.ReadInt32(); // 08 stream.Position = header_size; info.DataSize = reader.ReadInt32(); // XX+00 info.Width = reader.ReadUInt16(); // XX+04 info.Height = reader.ReadUInt16(); // XX+06 info.DataOffset = header_size+8; if (0 != (info.Flags & 4)) { stream.Position = 0x14; info.OffsetX = reader.ReadInt16(); info.OffsetY = reader.ReadInt16(); } return info; } }
public override ImageData Read(Stream stream, ImageMetaData info) { byte[] pixels = new byte[info.Width * info.Height * 4]; using (var input = new ArcView.Reader(stream)) { input.BaseStream.Position = 12; uint[] offset_table = new uint[info.Height]; for (uint i = 0; i < info.Height; ++i) { offset_table[i] = input.ReadUInt32(); } long base_offset = input.BaseStream.Position; int dst = 0; foreach (var offset in offset_table) { input.BaseStream.Position = base_offset + offset; for (int x = 0; x < info.Width;) { byte alpha = input.ReadByte(); int count = input.ReadByte(); if (0 == count) { count = 0x100; } if (0 == alpha) { dst += count * 4; } else { for (int n = 0; n < count; ++n) { pixels[dst + 3] = alpha; pixels[dst + 2] = input.ReadByte(); pixels[dst + 1] = input.ReadByte(); pixels[dst] = input.ReadByte(); dst += 4; } } x += count; } } return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels)); } }
protected List <Entry> ReadIndex(Stream file) { long base_offset = file.Position; using (var input = new ArcView.Reader(file)) { int count = Binary.BigEndian(input.ReadInt16()); if (!IsSaneCount(count)) { return(null); } base_offset += Binary.BigEndian(input.ReadUInt32()); if (base_offset >= file.Length || base_offset < 15 * count) { return(null); } var dir = new List <Entry>(); for (int i = 0; i < count; ++i) { if (base_offset - file.Position < 15) { return(null); } var name = file.ReadCString(); if (base_offset - file.Position < 13 || 0 == name.Length) { return(null); } var entry = FormatCatalog.Instance.Create <NsaEntry> (name); byte compression_type = input.ReadByte(); entry.Offset = Binary.BigEndian(input.ReadUInt32()) + base_offset; entry.Size = Binary.BigEndian(input.ReadUInt32()); if (!entry.CheckPlacement(file.Length)) { return(null); } entry.UnpackedSize = Binary.BigEndian(input.ReadUInt32()); entry.IsPacked = compression_type != 0; switch (compression_type) { case 0: entry.CompressionType = Compression.None; break; case 1: entry.CompressionType = Compression.SPB; break; case 2: entry.CompressionType = Compression.LZSS; break; case 4: entry.CompressionType = Compression.NBZ; break; default: entry.CompressionType = Compression.Unknown; break; } dir.Add(entry); } return(dir); } }
static void LzssUnpack(Stream input, byte[] output) { var frame = new byte[0x1000]; int frame_pos = 0xFEE; using (var lz = new ArcView.Reader(input)) { int dst = 0; int bits = 1; while (dst < output.Length) { if (1 == bits) { bits = lz.ReadByte() | 0x100; } if (0 != (bits & 1)) { byte b = lz.ReadByte(); output[dst++] = b; frame[frame_pos++] = b; frame_pos &= 0xFFF; } else { byte lo = lz.ReadByte(); byte hi = lz.ReadByte(); int offset = (hi & 0xF0) << 4 | lo; int count = Math.Min((~hi & 0xF) + 3, output.Length - dst); for (int i = 0; i < count; ++i) { byte b = frame[offset++ & 0xFFF]; output[dst++] = b; frame[frame_pos++] = b; frame_pos &= 0xFFF; } } bits >>= 1; } } }
public BmrDecoder(Stream input) { input.Position = 3; using (var header = new ArcView.Reader(input)) { m_step = header.ReadByte(); m_final_size = header.ReadInt32(); m_key = header.ReadInt32(); int unpacked_size = header.ReadInt32(); m_output = new byte[unpacked_size]; m_input = new MsbBitStream(input, true); } }
Stream Unpack(Stream input) { using (var reader = new ArcView.Reader(input)) { var output = new MemoryStream(); var buffer = new byte[0x10000]; for (;;) { int ctl = input.ReadByte(); if (-1 == ctl || 0xFF == ctl) { break; } int count = reader.ReadInt32(); if (3 == ctl) { byte b = reader.ReadByte(); for (int i = 0; i < count; ++i) { output.WriteByte(b); } } else { while (count > 0) { int chunk = Math.Min(count, buffer.Length); int read = reader.Read(buffer, 0, chunk); output.Write(buffer, 0, read); count -= chunk; } } } output.Position = 0; return(output); } }
public override ImageMetaData ReadMetaData(Stream stream) { stream.Position = 4; if (stream.ReadByte() != '3') { return(null); } var rect = new Rectangle(0, 0, 0, 0); using (var reader = new ArcView.Reader(stream)) { int count = reader.ReadInt32(); for (int i = 0; i < count; ++i) { reader.ReadInt32(); int name_length = reader.ReadByte(); reader.BaseStream.Seek(name_length, SeekOrigin.Current); int x = reader.ReadInt32(); int y = reader.ReadInt32(); int w = reader.ReadInt32() - x; int h = reader.ReadInt32() - y; if (name_length > 0) { var part_rect = new Rectangle(x, y, w, h); rect = Rectangle.Union(rect, part_rect); } reader.BaseStream.Seek(12, SeekOrigin.Current); } uint data_size = reader.ReadUInt32(); if (data_size > stream.Length - stream.Position) { return(null); } return(ReadCompressionMetaData(reader, rect)); } }
public override ImageMetaData ReadMetaData(Stream stream) { using (var file = new ArcView.Reader (stream)) { stream.Seek (3, SeekOrigin.Current); byte id = file.ReadByte(); uint data_size = file.ReadUInt32(); uint width = file.ReadUInt32(); uint height = file.ReadUInt32(); uint stride = file.ReadUInt32(); if (stride < width) throw new NotSupportedException(); if (stride*height != data_size) return null; return new MfgMetaData { Width = width, Height = height, BPP = (int)(stride*8/width), Type = id, Stride = (int)stride, }; } }
ImageData ReadV5(Stream stream, TlgMetaData info) { using (var src = new ArcView.Reader(stream)) { int width = (int)info.Width; int height = (int)info.Height; int colors = info.BPP / 8; int blockheight = src.ReadInt32(); int blockcount = (height - 1) / blockheight + 1; // skip block size section src.BaseStream.Seek(blockcount * 4, SeekOrigin.Current); int stride = width * 4; var image_bits = new byte[height * stride]; var text = new byte[4096]; for (int i = 0; i < 4096; ++i) { text[i] = 0; } var inbuf = new byte[blockheight * width + 10]; byte [][] outbuf = new byte[4][]; for (int i = 0; i < colors; i++) { outbuf[i] = new byte[blockheight * width + 10]; } int z = 0; int prevline = -1; for (int y_blk = 0; y_blk < height; y_blk += blockheight) { // read file and decompress for (int c = 0; c < colors; c++) { byte mark = src.ReadByte(); int size; size = src.ReadInt32(); if (mark == 0) { // modified LZSS compressed data if (size != src.Read(inbuf, 0, size)) { return(null); } z = TVPTLG5DecompressSlide(outbuf[c], inbuf, size, text, z); } else { // raw data src.Read(outbuf[c], 0, size); } } // compose colors and store int y_lim = y_blk + blockheight; if (y_lim > height) { y_lim = height; } int outbuf_pos = 0; for (int y = y_blk; y < y_lim; y++) { int current = y * stride; int current_org = current; if (prevline >= 0) { // not first line switch (colors) { case 3: TVPTLG5ComposeColors3To4(image_bits, current, prevline, outbuf, outbuf_pos, width); break; case 4: TVPTLG5ComposeColors4To4(image_bits, current, prevline, outbuf, outbuf_pos, width); break; } } else { // first line switch (colors) { case 3: for (int pr = 0, pg = 0, pb = 0, x = 0; x < width; x++) { int b = outbuf[0][outbuf_pos + x]; int g = outbuf[1][outbuf_pos + x]; int r = outbuf[2][outbuf_pos + x]; b += g; r += g; image_bits[current++] = (byte)(pb += b); image_bits[current++] = (byte)(pg += g); image_bits[current++] = (byte)(pr += r); image_bits[current++] = 0xff; } break; case 4: for (int pr = 0, pg = 0, pb = 0, pa = 0, x = 0; x < width; x++) { int b = outbuf[0][outbuf_pos + x]; int g = outbuf[1][outbuf_pos + x]; int r = outbuf[2][outbuf_pos + x]; int a = outbuf[3][outbuf_pos + x]; b += g; r += g; image_bits[current++] = (byte)(pb += b); image_bits[current++] = (byte)(pg += g); image_bits[current++] = (byte)(pr += r); image_bits[current++] = (byte)(pa += a); } break; } } outbuf_pos += width; prevline = current_org; } } PixelFormat format = 4 == colors ? PixelFormats.Bgra32 : PixelFormats.Bgr32; return(ImageData.Create(info, format, null, image_bits, stride)); } }
byte[] Unpack(Stream stream) { using (var input = new ArcView.Reader(stream)) { uint unpacked_size = input.ReadUInt32(); int remaining = input.ReadInt32() - 9; var output = new byte[unpacked_size]; byte control_code = input.ReadByte(); int dst = 0; while (remaining > 0) { byte b = input.ReadByte(); --remaining; if (b != control_code) { output[dst++] = b; continue; } b = input.ReadByte(); --remaining; if (b == control_code) { output[dst++] = b; continue; } if (b > control_code) { --b; } int count = b >> 3; if (0 != (b & 4)) { count |= input.ReadByte() << 5; --remaining; } count += 4; int offset; switch (b & 3) { case 0: offset = input.ReadByte(); --remaining; break; case 1: offset = input.ReadUInt16(); remaining -= 2; break; case 2: offset = input.ReadUInt16(); offset |= input.ReadByte() << 16; remaining -= 3; break; default: throw new InvalidFormatException("DX decompression failed"); } ++offset; Binary.CopyOverlapped(output, dst - offset, dst, count); dst += count; } return(output); } }
private void UnpackV1() { using (var src = new ArcView.Reader(m_input)) { byte[] window = new byte[0x10000]; int flag = 0; int win_pos = 0; int dst = 0; while (dst < m_output.Length) { flag >>= 1; if (0 == (flag & 0x100)) { flag = src.ReadByte() | 0xff00; } if (0 != (flag & 1)) { byte dat = src.ReadByte(); window[win_pos++] = dat; win_pos &= 0xffff; m_output[dst++] = dat; } else { byte control = src.ReadByte(); int count, offset; if (control >= 0xc0) { offset = ((control & 3) << 8) | src.ReadByte(); count = 4 + ((control >> 2) & 0xf); } else if (0 != (control & 0x80)) { offset = control & 0x1f; count = 2 + ((control >> 5) & 3); if (0 == offset) { offset = src.ReadByte(); } } else if (0x7f == control) { count = 2 + src.ReadUInt16(); offset = src.ReadUInt16(); } else { offset = src.ReadUInt16(); count = control + 4; } offset = win_pos - offset; for (int k = 0; k < count && dst < m_output.Length; k++) { offset &= 0xffff; byte dat = window[offset++]; window[win_pos++] = dat; win_pos &= 0xffff; m_output[dst++] = dat; } } } } }
public override ImageMetaData ReadMetaData(Stream stream) { stream.Seek (3, SeekOrigin.Current); using (var input = new ArcView.Reader (stream)) { int bpp = input.ReadByte(); int x = 0; int y = 0; int type = bpp; int header_size = 8; if (2 == type) { bpp = input.ReadByte(); header_size = 13; } else if (1 == type) { bpp = input.ReadByte(); x = input.ReadInt16(); y = input.ReadInt16(); header_size = 13; } else type = 0; if (8 != bpp && 24 != bpp && 32 != bpp) return null; uint w = input.ReadUInt16(); uint h = input.ReadUInt16(); if (2 == type) { x = input.ReadInt16(); y = input.ReadInt16(); } return new ElgMetaData { Width = w, Height = h, OffsetX = x, OffsetY = y, BPP = bpp, Type = type, HeaderSize = header_size, }; } }
protected override IEnumerator <int> Unpack() { var freq = new ushort[0x100]; var table2 = new byte[0xFFFF00]; var table3 = new uint[0x100]; var table4 = new uint[0x100]; using (var reader = new ArcView.Reader(BaseStream)) { for (;;) { int chunk_len = reader.ReadInt32(); byte ctl = reader.ReadByte(); for (int i = 0; i < 0x100; ++i) { freq[i] = 0; } switch (ctl & 0x1F) { case 1: int count = reader.ReadByte(); while (count-- > 0) { byte i = reader.ReadByte(); byte b = reader.ReadByte(); if (0 != (b & 0x80)) { freq[i] = (ushort)(b & 0x7F); } else { freq[i] = (ushort)((reader.ReadByte() << 7) | b); } } break; case 2: for (int i = 0; i < 256; i++) { byte b = reader.ReadByte(); if (0 != (b & 0x80)) { freq[i] = (ushort)(b & 0x7F); } else { freq[i] = (ushort)((reader.ReadByte() << 7) | b); } } break; } uint f = 0; for (int i = 0; i < 0x100; i++) { table3[i] = f; table4[i] = freq[i]; for (int j = freq[i]; j > 0; --j) { table2[f++] = (byte)i; } } uint range = 0xC0000000; uint high = Binary.BigEndian(reader.ReadUInt32()); for (int i = 0; i < chunk_len; i++) { uint index = high / (range >> 12); byte c = table2[index]; if (YieldByte(c)) { yield return(YieldOffset); } high -= (range >> 12) * table3[c]; range = (range >> 12) * table4[c]; while (0 == (range & 0xFF000000)) { high = (high << 8) | reader.ReadByte(); range <<= 8; } } if (0 == (ctl & 0x80)) { break; } } } }
static void LzssUnpack(Stream input, byte[] output) { var frame = new byte[0x1000]; int frame_pos = 0xFEE; using (var lz = new ArcView.Reader (input)) { int dst = 0; int bits = 1; while (dst < output.Length) { if (1 == bits) bits = lz.ReadByte() | 0x100; if (0 != (bits & 1)) { byte b = lz.ReadByte(); output[dst++] = b; frame[frame_pos++] = b; frame_pos &= 0xFFF; } else { byte lo = lz.ReadByte(); byte hi = lz.ReadByte(); int offset = (hi & 0xF0) << 4 | lo; int count = Math.Min ((~hi & 0xF) + 3, output.Length-dst); for (int i = 0; i < count; ++i) { byte b = frame[offset++ & 0xFFF]; output[dst++] = b; frame[frame_pos++] = b; frame_pos &= 0xFFF; } } bits >>= 1; } } }
byte[] Unpack(Stream stream) { using (var input = new ArcView.Reader (stream)) { uint unpacked_size = input.ReadUInt32(); int remaining = input.ReadInt32() - 9; var output = new byte[unpacked_size]; byte control_code = input.ReadByte(); int dst = 0; while (remaining > 0) { byte b = input.ReadByte(); --remaining; if (b != control_code) { output[dst++] = b; continue; } b = input.ReadByte(); --remaining; if (b == control_code) { output[dst++] = b; continue; } if (b > control_code) --b; int count = b >> 3; if (0 != (b & 4)) { count |= input.ReadByte() << 5; --remaining; } count += 4; int offset; switch (b & 3) { case 0: offset = input.ReadByte(); --remaining; break; case 1: offset = input.ReadUInt16(); remaining -= 2; break; case 2: offset = input.ReadUInt16(); offset |= input.ReadByte() << 16; remaining -= 3; break; default: throw new InvalidFormatException ("DX decompression failed"); } ++offset; Binary.CopyOverlapped (output, dst - offset, dst, count); dst += count; } return output; } }
protected List<Entry> ReadIndex(Stream file) { long base_offset = file.Position; using (var input = new ArcView.Reader (file)) { int count = Binary.BigEndian (input.ReadInt16()); if (!IsSaneCount (count)) return null; base_offset += Binary.BigEndian (input.ReadUInt32()); if (base_offset >= file.Length || base_offset < 15 * count) return null; var dir = new List<Entry>(); for (int i = 0; i < count; ++i) { if (base_offset - file.Position < 15) return null; var name = file.ReadCString(); if (base_offset - file.Position < 13 || 0 == name.Length) return null; var entry = FormatCatalog.Instance.Create<NsaEntry> (name); byte compression_type = input.ReadByte(); entry.Offset = Binary.BigEndian (input.ReadUInt32()) + base_offset; entry.Size = Binary.BigEndian (input.ReadUInt32()); if (!entry.CheckPlacement (file.Length)) return null; entry.UnpackedSize = Binary.BigEndian (input.ReadUInt32()); entry.IsPacked = compression_type != 0; switch (compression_type) { case 0: entry.CompressionType = Compression.None; break; case 1: entry.CompressionType = Compression.SPB; break; case 2: entry.CompressionType = Compression.LZSS; break; case 4: entry.CompressionType = Compression.NBZ; break; default: entry.CompressionType = Compression.Unknown; break; } dir.Add (entry); } return dir; } }
public BmrDecoder(Stream input) { input.Position = 3; using (var header = new ArcView.Reader (input)) { m_step = header.ReadByte(); m_final_size = header.ReadInt32(); m_key = header.ReadInt32(); int unpacked_size = header.ReadInt32(); m_output = new byte[unpacked_size]; m_input = new MsbBitStream (input, true); } }