public override ArcFile TryOpen(ArcView file) { if (!file.Name.HasExtension(".lay")) { return(null); } int tile_count = file.View.ReadInt32(0); int coord_count = file.View.ReadInt32(4); if (!IsSaneCount(tile_count) || !IsSaneCount(coord_count)) { return(null); } var base_name = Path.GetFileNameWithoutExtension(file.Name).TrimEnd('_'); var png_name = VFS.ChangeFileName(file.Name, base_name + ".png"); if (!VFS.FileExists(png_name)) { return(null); } ImageData image; var png_entry = VFS.FindFile(png_name); using (var decoder = VFS.OpenImage(png_entry)) image = decoder.Image; using (var input = file.CreateStream()) using (var index = new BinaryReader(input)) { input.Position = 8; var dir = new List <Entry> (tile_count); for (int i = 0; i < tile_count; ++i) { uint id = index.ReadUInt32(); int first = index.ReadInt32(); int count = index.ReadInt32(); var name = string.Format("{0}#{1:X8}", base_name, id); var entry = new LayEntry { Name = name, Type = "image", Offset = 0, Id = id, First = first, Count = count }; dir.Add(entry); } var tiles = new List <LayCoord> (coord_count); for (int i = 0; i < coord_count; ++i) { var tile = new LayCoord(); tile.TargetX = index.ReadSingle() + 1; tile.TargetY = index.ReadSingle() + 1; tile.SourceX = index.ReadSingle() - 1; tile.SourceY = index.ReadSingle() - 1; tiles.Add(tile); } return(new LayArchive(file, this, dir, image.Bitmap, tiles)); } }
void LoadPreviewImage(PreviewFile preview) { try { using (var data = VFS.OpenImage(preview.Entry)) { SetPreviewImage(preview, data.Image.Bitmap); } } catch (Exception X) { SetStatusText(X.Message); } }
void LoadPreviewImage(PreviewFile preview) { try { using (var data = VFS.OpenImage(preview.Entry)) { SetPreviewImage(preview, data.Image.Bitmap, data.SourceFormat); } } catch (Exception X) { Dispatcher.Invoke(ResetPreviewPane); SetStatusText(X.Message); } }
public override IImageDecoder OpenImage(ArcFile arc, Entry entry) { var input = arc.OpenBinaryEntry(entry); int length = (int)(input.Length - 0x10); if ((length & 3) != 0) { return(ImageFormatDecoder.Create(input)); } uint width = input.ReadUInt32(); uint height = input.ReadUInt32(); int buf_width = input.ReadInt32(); int buf_height = input.ReadInt32(); var info = new ImageMetaData { Width = width, Height = height, BPP = 32 }; if (DefaultVisualMap.Value.ContainsKey(entry.Name)) { var diff_info = DefaultVisualMap.Value[entry.Name]; if (VFS.FileExists(diff_info.BaseFileName)) { var base_entry = VFS.FindFile(diff_info.BaseFileName); using (var visbase = VFS.OpenImage(base_entry)) { var base_decoder = visbase as Gx4ImageDecoder; if (base_decoder != null) { info.OffsetX = diff_info.PosX; info.OffsetY = diff_info.PosY; var pixels = base_decoder.ReadPixels(); return(new Gx4OverlayDecoder(pixels, base_decoder.Info, input, info)); } } } } return(new Gx4ImageDecoder(input, info)); }