private ImageSource GetGlobalMapImagefFromPcx(string aFileName) { string _path = Path.Combine(this.FGlobalMapsFolder, aFileName); PcxObject _pcx = null; if (File.Exists(_path)) { _pcx = new PcxObject(aFileName); using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read)) _pcx.Load(input); } else { if (this.SlfFile != null) { SlfFile.Record _record = this.SlfFile.Records .SingleOrDefault(x => x.FileName.ToUpperInvariant() == aFileName.ToUpperInvariant()); if (_record != null) { _pcx = new PcxObject(aFileName); using (MemoryStream input = new MemoryStream(_record.Data)) _pcx.Load(input); } } } if (_pcx == null) { return(null); } List <Color> _palette = _pcx.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); BitmapPalette _pb = new BitmapPalette(_palette); PixelFormat _pf = PixelFormats.Indexed8; BitmapSource _bitmap = BitmapSource.Create( _pcx.Width, _pcx.Height, 96, 96, _pf, _pb, _pcx.ImageData, _pcx.Width * _pf.BitsPerPixel / 8); return(_bitmap); }
private void FLoadSlfWorker_DoWork(object sender, DoWorkEventArgs e) { this.IsBusy = true; try { string _slfFileName = (string)e.Argument; SlfFile _slfFile = new SlfFile(_slfFileName); _slfFile.LoadRecords(); var _jsdRecords = _slfFile.Records.Where(x => x.FileNameExtention.ToLower() == ".jsd"); int _recNum = _jsdRecords.Count(); foreach (SlfFile.Record _record in _jsdRecords) { JsdFileViewModel _jsdFileViewModel = null; MemoryStream _ms = new MemoryStream(_record.Data); JsdFile _jsdFile = JsdFile.Load(_ms); _ms.Close(); _jsdFileViewModel = new JsdFileViewModel(_jsdFile, _record.FileName); SlfFile.Record _stiRecord = _slfFile.Records .Where(x => x.FileName.ToLower() == _record.FileName.ToLower().Replace(".jsd", ".sti")) .SingleOrDefault(); if (_stiRecord != null) { _ms = new MemoryStream(_stiRecord.Data); IStci _stci = StciLoader.LoadStci(_ms); if (_stci.IsIndexed) { _jsdFileViewModel.StciFile = (StciIndexed)_stci; } } this.JsdFilesCount++; this.FLoadSlfWorker.ReportProgress(100 * this.JsdFilesCount / _recNum, _jsdFileViewModel); } } finally { this.IsBusy = false; } }
private void LoadTileSet() { string _ja2SetData = System.IO.Path.Combine(this.DataFolder, @"BinaryData\JA2SET.DAT"); if (File.Exists(_ja2SetData)) { using (Stream _fs = new FileStream(_ja2SetData, FileMode.Open, FileAccess.Read)) { TileSet.Load(_fs); } } else { string _binaryDataFile = Path.Combine(this.DataFolder, "Binarydata.slf"); if (File.Exists(_binaryDataFile)) { SlfFile _binaryDataSlf = new SlfFile(_binaryDataFile); _binaryDataSlf.LoadRecords(); SlfFile.Record _ja2set = _binaryDataSlf.Records.SingleOrDefault(x => x.FileName.ToUpperInvariant() == "JA2SET.DAT"); if (_ja2set != null) { using (MemoryStream _ms = new MemoryStream(_ja2set.Data)) { TileSet.Load(_ms); } } else { throw new FileNotFoundException( String.Format("Record JA2SET.DAT is not found in file {0}.", _binaryDataFile)); } } else { throw new FileNotFoundException( String.Format("Files {0}, {1} are not found.", _ja2SetData, _binaryDataFile)); } } }
private ImageSource GetGlobalMapImagefFromSti(string aFileName) { string _path = Path.Combine(this.FGlobalMapsFolder, aFileName); IStci _sti = null; if (File.Exists(_path)) { using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read)) _sti = StciLoader.LoadStci(input); } else { if (this.SlfFile != null) { SlfFile.Record _record = this.SlfFile.Records .SingleOrDefault(x => x.FileName.ToUpperInvariant() == aFileName.ToUpperInvariant()); if (_record != null) { using (MemoryStream input = new MemoryStream(_record.Data)) _sti = StciLoader.LoadStci(input); } } } if (_sti == null) { ImageSourceConverter _isc = new ImageSourceConverter(); ImageSource _is = (ImageSource)_isc.ConvertFromString("MAP_STUB.bmp"); return(_is); } else if (_sti is StciIndexed) { StciIndexed _stciIndexed = (StciIndexed)_sti; List <Color> _palette = _stciIndexed.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); StciSubImage _subImage = _stciIndexed.Images[0]; StructureImage _image = new StructureImage(_subImage, _palette); BitmapPalette _pb = new BitmapPalette(_palette); PixelFormat _pf = PixelFormats.Indexed8; BitmapSource _bitmap = BitmapSource.Create( _subImage.Header.Width, _subImage.Header.Height, 96, 96, _pf, _pb, _subImage.ImageData, _subImage.Header.Width * _pf.BitsPerPixel / 8); return(_bitmap); } else if (_sti is StciRgb) { StciRgb _stciRgb = (StciRgb)_sti; PixelFormat _pf = PixelFormats.Bgr565; BitmapSource _bitmap = BitmapSource.Create( _stciRgb.Header.ImageWidth, _stciRgb.Header.ImageHeight, 96, 96, _pf, null, _stciRgb.ImageData, _stciRgb.Header.ImageWidth * _pf.BitsPerPixel / 8); return(_bitmap); } return(null); }
public void LoadMapTileSet(Map aMap) { for (int k = 0; k < TileSet.NumOfTileTypes; k++) { string _fileName = TileSet.TileSets[aMap.TilesetID].TileSurfaceFilenames[k]; int _tilesetId = aMap.TilesetID; if (_fileName == String.Empty) { _fileName = TileSet.TileSets[0].TileSurfaceFilenames[k]; _tilesetId = 0; } _fileName = Path.Combine(_tilesetId.ToString(), _fileName); string _path = Path.Combine(this.FTilesetFolder, _fileName); StciIndexed _sti = null; if (File.Exists(_path)) { //using(FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read)) _sti = (StciIndexed)StciLoader.LoadStci(_path); } else { if (File.Exists(this.FTilesetFileName)) { SlfFile.Record _record = this.TilesetSlfFile.Records .SingleOrDefault(x => x.State == 0 && x.FileName.ToUpperInvariant() == _fileName.ToUpperInvariant()); if (_record != null) { using (MemoryStream input = new MemoryStream(_record.Data)) _sti = (StciIndexed)StciLoader.LoadStci(input, _fileName); } else { throw new FileNotFoundException( String.Format("Record {0} is not found in file {1}.", _fileName, this.FTilesetFileName)); } } else { throw new FileNotFoundException( String.Format("Files {0}, {1} are not found.", _path, this.FTilesetFileName)); } } JsdFile _jsd = null; _path = Path.ChangeExtension(_path, ".jsd"); if (File.Exists(_path)) { using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read)) { _jsd = JsdFile.Load(input); } } else { if (File.Exists(this.FTilesetFileName)) { _fileName = Path.ChangeExtension(_fileName, "jsd"); SlfFile.Record _record = this.TilesetSlfFile.Records .SingleOrDefault(x => x.FileName.ToUpperInvariant() == _fileName.ToUpperInvariant()); if (_record != null) { using (MemoryStream input = new MemoryStream(_record.Data)) _jsd = JsdFile.Load(input); } //else //{ // throw new FileNotFoundException( // String.Format("Record {0} is not found in file {1}.", _fileName, this.FTilesetFileName)); //} } //else //{ // throw new FileNotFoundException( // String.Format("Files {0}, {1} are not found.", _path, this.FTilesetFileName)); //} } aMap.MapTileSet[k] = new Map.TileObject(_sti, _jsd); } }